~shulhan/awwan

a1339c8b1fb34d272426f97ca42cecd7971e627c — Shulhan 10 months ago ed7f737
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
1 files changed, 41 insertions(+), 30 deletions(-)

M _sys/usr/share/bash-completion/completions/awwan
M _sys/usr/share/bash-completion/completions/awwan => _sys/usr/share/bash-completion/completions/awwan +41 -30
@@ 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