Crates.io | computergeneration |
lib.rs | computergeneration |
version | 0.2.0 |
source | src |
created_at | 2020-12-05 20:49:49.768996 |
updated_at | 2021-02-15 21:04:41.527465 |
description | compgen but all wrong |
homepage | https://github.com/LPGhatguy/computergeneration |
repository | |
max_upload_size | |
id | 319936 |
size | 17,921 |
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
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.
Imagine you spelled out "comp gen" and used tab-completion to finish each word... but you got the wrong word both times!
Licensed under the MIT license. See LICENSE.txt or http://opensource.org/licenses/MIT for details.