3 unstable releases

0.2.0 Feb 15, 2021
0.1.1 Feb 15, 2021
0.1.0 Dec 5, 2020

#11 in #primary

MIT license

7KB
80 lines

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:

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] <pattern>

FLAGS:
    -h, --help
            Prints help information

    -V, --version
            Prints version information


OPTIONS:
        --case <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>
            Pattern to complete against

Basic Usage

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

# Jump to the machine's projects directory ($PROJ) and optionally a project
# inside it.
function proj() {
	cd "$PROJ/$1"
}

function _proj_complete() {
	COMPREPLY=( $(compgen -W "$(\ls -1 $PROJ)" "${COMP_WORDS[1]}") )
	return 0
}
complete -F _proj_complete proj

I replaced it with this, using computergeneration:

# Jump to the machine's projects directory ($PROJ) and optionally a project
# inside it.
function proj() {
	cd "$PROJ/$1"
}

function _proj_complete() {
	COMPREPLY=( $(\ls -1 $PROJ | computergeneration "${COMP_WORDS[1]}") )
	return 0
}
complete -F _proj_complete 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.

Dependencies

~4MB
~69K SLoC