Skip to content

Commit

Permalink
Replace hyphen with underscore for command auto-completion (iterative…
Browse files Browse the repository at this point in the history
…#2596)

* Replace hyphen with underscore for bash auto-completion

* Write function to replace hyphen and check for flags

* Nest function inside `_dvc`
  • Loading branch information
algomaster99 authored and efiop committed Oct 11, 2019
1 parent 4426485 commit ed89725
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions scripts/completion/dvc.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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=()
Expand All @@ -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
Expand Down

0 comments on commit ed89725

Please sign in to comment.