computergeneration

computergeneration on crates.io

computergeneration is a partial compgen replacement whose primary goal is to provide case-insensitive completions, since compgen doesn't seem to be able to do that. It's written in Rust, and you can install it right now:

bash cargo install computergeneration

``` $ computergeneration --help computergeneration 0.2.0 Generates completions based on a word list and a prompt.

Word list is expected to be provided via stdin, and newline-delimited.

USAGE: computergeneration.exe [OPTIONS]

FLAGS: -h, --help Prints help information

-V, --version
        Prints version information

OPTIONS: --case Case matching strategy to use

        * auto: Case insensitive if pattern is all lowercase
        * sensitive: Always case sensitive
        * insensitive: Always case insensitive [default: auto]

ARGS: Pattern to complete against ```

Basic Usage

I had a sort of janky Bash completion script that looked like this with compgen:

```bash

Jump to the machine's projects directory ($PROJ) and optionally a project

inside it.

function proj() { cd "$PROJ/$1" }

function projcomplete() { COMPREPLY=( $(compgen -W "$(\ls -1 $PROJ)" "${COMPWORDS[1]}") ) return 0 } complete -F _projcomplete proj ```

I replaced it with this, using computergeneration:

```bash

Jump to the machine's projects directory ($PROJ) and optionally a project

inside it.

function proj() { cd "$PROJ/$1" }

function projcomplete() { COMPREPLY=( $(\ls -1 $PROJ | computergeneration "${COMPWORDS[1]}") ) return 0 } complete -F _projcomplete proj ```

Suddenly, I'm able to tab-complete project names and move into them even when I forget how they're capitalized!

This is made a lot less useful by the fact that I also use fzf-tab-completion, but it was a nice exercise.

Where did this name come from?

Imagine you spelled out "comp gen" and used tab-completion to finish each word... but you got the wrong word both times!

License

Licensed under the MIT license. See LICENSE.txt or http://opensource.org/licenses/MIT for details.