diff options
| author | Shulhan <ms@kilabit.info> | 2024-01-15 23:41:53 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2024-01-16 00:09:25 +0700 |
| commit | a1339c8b1fb34d272426f97ca42cecd7971e627c (patch) | |
| tree | 560fea82a6fe35664befa3a41011bd95a2c98fdf | |
| parent | ed7f73739ea5ad270071872a8e373dd03f2e2935 (diff) | |
| download | awwan-a1339c8b1fb34d272426f97ca42cecd7971e627c.tar.xz | |
bash-completion: use command env-keys to show completion for env-get
After the env-get first parameter is filled, the file or directory,
we can show possible completion for the second parameter by printing
all keys under the path.
References: https://todo.sr.ht/~shulhan/awwan/10
| -rw-r--r-- | _sys/usr/share/bash-completion/completions/awwan | 69 |
1 files changed, 40 insertions, 29 deletions
diff --git a/_sys/usr/share/bash-completion/completions/awwan b/_sys/usr/share/bash-completion/completions/awwan index 40c8c80..ec68a6e 100644 --- a/_sys/usr/share/bash-completion/completions/awwan +++ b/_sys/usr/share/bash-completion/completions/awwan @@ -12,38 +12,49 @@ _awwan_completions() local key=${COMP_WORDS[2]} case "$cmd" in - decrypt) + decrypt) + COMPREPLY=($(compgen -A file -X "?(.git|*.log)" -- "$key")) + ;; + encrypt) + COMPREPLY=($(compgen -A file -X "?(.git|*.log)" -- "$key")) + ;; + env-get) + case $COMP_CWORD in + 2) COMPREPLY=($(compgen -A file -X "?(.git|*.log)" -- "$key")) ;; - encrypt) - COMPREPLY=($(compgen -A file -X "?(.git|*.log)" -- "$key")) - ;; - env-get) - ;; - env-set) - ;; - help) - ;; - local) - COMPREPLY=($(compgen -A file -X "?(*.log|.*)" -- "$key")) - ;; - play) - COMPREPLY=($(compgen -A file -X "?(*.log|.*)" -- "$key")) - ;; - serve) - COMPREPLY=($(compgen -A directory -- "$key")) - ;; - version) - ;; - *) - if [[ -z $cmd ]]; then - COMPREPLY=("${commands[@]}") - else - local list="${commands[@]}" - COMPREPLY=($(compgen -W "$list" -- "$cmd")) - fi + 3) + local listKey=$(awwan env-keys "${key}" 2>/dev/null) + local argKey=${COMP_WORDS[${COMP_CWORD}]} + local filteredKeys=$(compgen -W "${listKey}" -- "${argKey}") + COMPREPLY=(${filteredKeys}) ;; + esac + ;; + env-set) + ;; + help) + ;; + local) + COMPREPLY=($(compgen -A file -X "?(*.log|.*)" -- "$key")) + ;; + play) + COMPREPLY=($(compgen -A file -X "?(*.log|.*)" -- "$key")) + ;; + serve) + COMPREPLY=($(compgen -A directory -- "$key")) + ;; + version) + ;; + *) + if [[ -z $cmd ]]; then + COMPREPLY=("${commands[@]}") + else + local list="${commands[@]}" + COMPREPLY=($(compgen -W "$list" -- "$cmd")) + fi + ;; esac } -complete -o bashdefault -F _awwan_completions awwan +complete -o nospace -o bashdefault -F _awwan_completions awwan |
