Replace hyphen with underscore for command auto-completion (#2596)

* Replace hyphen with underscore for bash auto-completion

* Write function to replace hyphen and check for flags

* Nest function inside `_dvc`
This commit is contained in:
Aman Sharma
2019-10-12 00:35:52 +03:00
committed by Ruslan Kuprieiev
parent 44264857c3
commit ed89725c98
+6 -2
View File
@@ -72,6 +72,10 @@ _dvc_version=''
# ${!x} -> ${hello} -> "world"
#
_dvc () {
replace_hyphen () {
echo $(echo $1 | sed 's/-/_/g')
}
local word="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=()
@@ -82,11 +86,11 @@ _dvc () {
*) COMPREPLY=($(compgen -W "$_dvc_commands" -- "$word")) ;;
esac
elif [ "${COMP_CWORD}" -eq 2 ]; then
local options_list="_dvc_${COMP_WORDS[1]}"
local options_list="_dvc_$(replace_hyphen ${COMP_WORDS[1]})"
COMPREPLY=($(compgen -W "$_dvc_global_options ${!options_list}" -- "$word"))
elif [ "${COMP_CWORD}" -eq 3 ]; then
local options_list="_dvc_${COMP_WORDS[1]}_${COMP_WORDS[2]}"
local options_list="_dvc_$(replace_hyphen ${COMP_WORDS[1]})_$(replace_hyphen ${COMP_WORDS[2]})"
COMPREPLY=($(compgen -W "$_dvc_global_options ${!options_list}" -- "$word"))
fi