From 15e97dcc402262f2be8562e88a14da5fcafefa8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= Date: Fri, 13 Oct 2023 20:43:09 +0800 Subject: [PATCH] Added kstore autocomplete --- bash/sources/16_keystore | 30 ++++++++++++++++++++++++++++-- bash/sources/17_kcontext | 1 - 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/bash/sources/16_keystore b/bash/sources/16_keystore index a25e2b7..205a635 100644 --- a/bash/sources/16_keystore +++ b/bash/sources/16_keystore @@ -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 "$@" ;; diff --git a/bash/sources/17_kcontext b/bash/sources/17_kcontext index c28ca47..df19590 100644 --- a/bash/sources/17_kcontext +++ b/bash/sources/17_kcontext @@ -24,7 +24,6 @@ function kcontext { function _kcontext { local CUR=${COMP_WORDS[COMP_CWORD]} local SCOPE=${COMP_WORDS[COMP_CWORD-1]} - local t COMPREPLY=()