Added kstore autocomplete

This commit is contained in:
斟酌 鵬兄 2023-10-13 20:43:09 +08:00
parent 6d1b390256
commit 15e97dcc40
2 changed files with 28 additions and 3 deletions

View File

@ -20,8 +20,6 @@ if [ -f "$RBASH_HOME/keystore.secret" ]; then
_AUTH_SECRET=$( cat "$RBASH_HOME/keystore.secret" )
fi
complete -W "add del get list query update search secret" kstore
function kstore {
case $1 in
add) shift; _kstoreadd "$@" ;;
@ -48,6 +46,34 @@ function kstore {
return $?
}
function _kstore {
local CUR=${COMP_WORDS[COMP_CWORD]}
local SCOPE=${COMP_WORDS[COMP_CWORD-1]}
local t
COMPREPLY=()
case "$SCOPE" in
kstore)
COMPREPLY=( $(compgen -W "add del get list query update search secret" -- $CUR) )
return
;;
get|update)
COMPREPLY=( $(compgen -W "$( _kstorequery "SELECT DISTINCT key FROM store" )" -- $CUR) )
;;
esac
t=${COMP_WORDS[COMP_CWORD-2]}
case "$t" in
get|update)
t=`_kstorequote "$SCOPE"`
COMPREPLY=( $(compgen -W "$( _kstorequery "SELECT DISTINCT prop FROM store WHERE key = '$t'" )" -- $CUR) )
;;
esac
}
complete -F _kstore kstore
function _kstoresecret {
case "$1" in
clear) shift; _kstoresecret-clear "$@" ;;

View File

@ -24,7 +24,6 @@ function kcontext {
function _kcontext {
local CUR=${COMP_WORDS[COMP_CWORD]}
local SCOPE=${COMP_WORDS[COMP_CWORD-1]}
local t
COMPREPLY=()