From ed89725c9896f3718f52f9507d8266fe8e5e59a6 Mon Sep 17 00:00:00 2001 From: Aman Sharma Date: Sat, 12 Oct 2019 03:05:52 +0530 Subject: [PATCH] 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` --- scripts/completion/dvc.bash | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/completion/dvc.bash b/scripts/completion/dvc.bash index d9f2babf9..95693042b 100644 --- a/scripts/completion/dvc.bash +++ b/scripts/completion/dvc.bash @@ -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