penguin/utils

my env utils

commit 15e97dcc402262f2be8562e88a14da5fcafefa8e

author斟酌 鵬兄 <tgckpg@gmail.com>
date2023-10-13T12:43:09Z
subjectAdded kstore autocomplete
commit 15e97dcc402262f2be8562e88a14da5fcafefa8e
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2023-10-13T12:43:09Z

    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=()