- Add clap_complete dependency for bash/zsh/fish/elvish/powershell - Add --generate-completion <shell> flag that prints completion script to stdout - profile.bash sources completions via command keep --generate-completion bash - @ and @@ aliases get completions via wrapper functions that delegate to _keep - README updated with Shell Completion section
62 lines
1007 B
Bash
Executable File
62 lines
1007 B
Bash
Executable File
#!/bin/bash
|
|
|
|
function __keep_preexec {
|
|
KEEP_META_command="$1"
|
|
KEEP_META_tty=${KEEP_META_tty:-$(tty)}
|
|
}
|
|
|
|
function __keep_preexec_init {
|
|
local found=false
|
|
local f
|
|
for f in "${preexec_functions[@]}"; do
|
|
if [[ $f = __keep_preexec ]]; then
|
|
found=true
|
|
break
|
|
fi
|
|
done
|
|
|
|
if [[ $found = false ]]; then
|
|
preexec_functions+=(__keep_preexec)
|
|
fi
|
|
}
|
|
|
|
function keep {
|
|
(
|
|
if [[ $BASH_SUBSHELL -le 2 ]]; then
|
|
export KEEP_META_command
|
|
fi
|
|
|
|
export KEEP_META_tty
|
|
|
|
exec keep "$@"
|
|
)
|
|
}
|
|
|
|
function @ {
|
|
keep --save "$@"
|
|
}
|
|
|
|
function @@ {
|
|
keep --get "$@"
|
|
}
|
|
|
|
# Shell completions
|
|
. <(command keep --generate-completion bash)
|
|
|
|
___keep_save_completion() {
|
|
COMP_WORDS=(keep --save "${COMP_WORDS[@]:1}")
|
|
COMP_CWORD=$((COMP_CWORD + 1))
|
|
_keep
|
|
}
|
|
|
|
___keep_get_completion() {
|
|
COMP_WORDS=(keep --get "${COMP_WORDS[@]:1}")
|
|
COMP_CWORD=$((COMP_CWORD + 1))
|
|
_keep
|
|
}
|
|
|
|
complete -F ___keep_save_completion @
|
|
complete -F ___keep_get_completion @@
|
|
|
|
__keep_preexec_init
|