computergeneration

Crates.iocomputergeneration
lib.rscomputergeneration
version0.2.0
sourcesrc
created_at2020-12-05 20:49:49.768996
updated_at2021-02-15 21:04:41.527465
descriptioncompgen but all wrong
homepagehttps://github.com/LPGhatguy/computergeneration
repository
max_upload_size
id319936
size17,921
Lucien Greathouse (LPGhatguy)

documentation

README

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.

Commit count: 0

cargo fmt