From 685916204a0ab655b6de6377fe8916230ce3b2e7 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 18 Feb 2020 22:42:53 +0000 Subject: [PATCH 1/5] completion: safer function names --- scripts/completion/dvc.bash | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/scripts/completion/dvc.bash b/scripts/completion/dvc.bash index 0727aa8ced..55ee1228a1 100644 --- a/scripts/completion/dvc.bash +++ b/scripts/completion/dvc.bash @@ -63,8 +63,14 @@ _dvc_version='' # Params # $1 - COMP_WORDS[1] -comp_command() { - local options_list="_dvc_$(replace_hyphen $1)" +_dvc_replace_hyphen() { + echo $1 | sed 's/-/_/g' +} + +# Params +# $1 - COMP_WORDS[1] +_dvc_comp_command() { + local options_list="_dvc_$(_dvc_replace_hyphen $1)" COMPREPLY=( $(compgen -W "$_dvc_global_options ${!options_list}" -- "$word") ) } @@ -72,10 +78,10 @@ comp_command() { # Params # $1 - COMP_WORDS[1] # $1 - COMP_WORDS[2] -comp_subcommand() { - local options_list="_dvc_$(replace_hyphen $1)_$(replace_hyphen $2)" +_dvc_comp_subcommand() { + local options_list="_dvc_$(_dvc_replace_hyphen $1)_$(_dvc_replace_hyphen $2)" if [ -z "${!options_list}" ]; then - comp_command $1 + _dvc_comp_command $1 else COMPREPLY=( $(compgen -W "$_dvc_global_options ${!options_list}" -- "$word") ) fi @@ -94,9 +100,6 @@ comp_subcommand() { # ${!x} -> ${hello} -> "world" # _dvc() { - replace_hyphen() { - echo $(echo $1 | sed 's/-/_/g') - } local word="${COMP_WORDS[COMP_CWORD]}" COMPREPLY=() @@ -107,9 +110,9 @@ _dvc() { *) COMPREPLY=($(compgen -W "$_dvc_commands" -- "$word")) ;; esac elif [ "${COMP_CWORD}" -eq 2 ]; then - comp_command ${COMP_WORDS[1]} + _dvc_comp_command ${COMP_WORDS[1]} elif [ "${COMP_CWORD}" -eq 3 ]; then - comp_subcommand ${COMP_WORDS[1]} ${COMP_WORDS[2]} + _dvc_comp_subcommand ${COMP_WORDS[1]} ${COMP_WORDS[2]} fi return 0 From 243c08ac2b612e33a2483f9d29c3e306bc669ea0 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 18 Feb 2020 22:45:41 +0000 Subject: [PATCH 2/5] completion: fix missing expansions Fixes #1923 --- scripts/completion/dvc.bash | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/scripts/completion/dvc.bash b/scripts/completion/dvc.bash index 55ee1228a1..1e85a8554c 100644 --- a/scripts/completion/dvc.bash +++ b/scripts/completion/dvc.bash @@ -15,15 +15,15 @@ _dvc_commands='add cache checkout commit config destroy diff fetch get-url get g _dvc_options='-h --help -V --version' _dvc_global_options='-h --help -q --quiet -v --verbose' -_dvc_add='-R --recursive -f --file --no-commit $(compgen -G *)' +_dvc_add='-R --recursive -f --file --no-commit $(compgen -G \*)' _dvc_cache='dir' _dvc_cache_dir=' --global --system --local -u --unset' -_dvc_checkout='-d --with-deps -R --recursive -f --force --relink $(compgen -G *.dvc)' -_dvc_commit='-f --force -d --with-deps -R --recursive $(compgen -G *.dvc)' +_dvc_checkout='-d --with-deps -R --recursive -f --force --relink $(compgen -G \*.dvc)' +_dvc_commit='-f --force -d --with-deps -R --recursive $(compgen -G \*.dvc)' _dvc_config='-u --unset --local --system --global' _dvc_destroy='-f --force' _dvc_diff='-t --show-json --checksums' -_dvc_fetch='-j --jobs -r --remote -a --all-branches -T --all-tags -d --with-deps -R --recursive $(compgen -G *.dvc)' +_dvc_fetch='-j --jobs -r --remote -a --all-branches -T --all-tags -d --with-deps -R --recursive $(compgen -G \*.dvc)' _dvc_get_url='' _dvc_get='-o --out --rev --show-url' _dvc_gc='-a --all-branches -T --all-tags -c --cloud -r --remote -f --force -p --projects -j --jobs' @@ -31,34 +31,34 @@ _dvc_import_url='-f --file' _dvc_import='-o --out --rev' _dvc_init='--no-scm -f --force' _dvc_install='' -_dvc_list='-R --recursive --outs-only --rev $(compgen -G *)' -_dvc_lock='$(compgen -G *.dvc)' +_dvc_list='-R --recursive --outs-only --rev $(compgen -G \*)' +_dvc_lock='$(compgen -G \*.dvc)' _dvc_metrics='add modify rmeove show' -_dvc_metrics_add='-t --type -x --xpath $(compgen -G *)' -_dvc_metrics_show='$(-t --type -x --xpath -a --all-branches -T --all-tags -R --recursive $(compgen -G *)' +_dvc_metrics_add='-t --type -x --xpath $(compgen -G \*)' +_dvc_metrics_show='$(-t --type -x --xpath -a --all-branches -T --all-tags -R --recursive $(compgen -G \*)' _dvc_metrics_diff='--targets -t --type -x --xpath -R --show-json' -_dvc_metrics_modify='-t --type -x --xpath $(compgen -G *)' -_dvc_metrics_remove='$(compgen -G *)' -_dvc_move='$(compgen -G *)' +_dvc_metrics_modify='-t --type -x --xpath $(compgen -G \*)' +_dvc_metrics_remove='$(compgen -G \*)' +_dvc_move='$(compgen -G \*)' _dvc_pipeline='list show' _dvc_pipeline_list='' -_dvc_pipeline_show='-c --commands -o --outs --ascii --dot --tree -l --locked $(compgen -G *.dvc)' -_dvc_pull='-j --jobs -r --remote -a --all-branches -T --all-tags -f --force -d --with-deps -R --recursive $(compgen -G *.dvc)' -_dvc_push='-j --jobs -r --remote -a --all-branches -T --all-tags -d --with-deps -R --recursive $(compgen -G *.dvc)' +_dvc_pipeline_show='-c --commands -o --outs --ascii --dot --tree -l --locked $(compgen -G \*.dvc)' +_dvc_pull='-j --jobs -r --remote -a --all-branches -T --all-tags -f --force -d --with-deps -R --recursive $(compgen -G \*.dvc)' +_dvc_push='-j --jobs -r --remote -a --all-branches -T --all-tags -d --with-deps -R --recursive $(compgen -G \*.dvc)' _dvc_remote='add default list modify remove' _dvc_remote_add='--global --system --local -d --default -f --force' _dvc_remote_default='--global --system --local -u --unset' _dvc_remote_list='--global --system --local' _dvc_remote_modify='--global --system --local -u --unset' _dvc_remote_remove='--global --system --local' -_dvc_remove='-o --outs -p --purge -f --force $(compgen -G *.dvc)' -_dvc_repro='-f --force -s --single-item -c --cwd -m --metrics --dry -i --interactive -p --pipeline -P --all-pipelines --ignore-build-cache --no-commit -R --recursive --downstream $(compgen -G *.dvc)' +_dvc_remove='-o --outs -p --purge -f --force $(compgen -G \*.dvc)' +_dvc_repro='-f --force -s --single-item -c --cwd -m --metrics --dry -i --interactive -p --pipeline -P --all-pipelines --ignore-build-cache --no-commit -R --recursive --downstream $(compgen -G \*.dvc)' _dvc_root='' _dvc_run='--no-exec -f --file -c --cwd -d --deps -o --outs -O --outs-no-cache --outs-persist --outs-persist-no-cache -m --metrics -M --metrics-no-cache -y --yes --overwrite-dvcfile --ignore-build-cache --remove-outs --no-commit -w --wdir' -_dvc_status='-j --jobs -r --remote -a --all-branches -T --all-tags -d --with-deps -c --cloud $(compgen -G *.dvc)' -_dvc_unlock='$(compgen -G *.dvc)' -_dvc_unprotect='$(compgen -G *)' -_dvc_update='--rev $(compgen -G *.dvc)' +_dvc_status='-j --jobs -r --remote -a --all-branches -T --all-tags -d --with-deps -c --cloud $(compgen -G \*.dvc)' +_dvc_unlock='$(compgen -G \*.dvc)' +_dvc_unprotect='$(compgen -G \*)' +_dvc_update='--rev $(compgen -G \*.dvc)' _dvc_version='' # Params From 4398fa6079339679f5d23dc39a9aa177da3957d2 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 18 Feb 2020 23:30:06 +0000 Subject: [PATCH 3/5] complete: bash: all filenames --- scripts/completion/dvc.bash | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/completion/dvc.bash b/scripts/completion/dvc.bash index 1e85a8554c..9a5e28baf1 100644 --- a/scripts/completion/dvc.bash +++ b/scripts/completion/dvc.bash @@ -15,7 +15,7 @@ _dvc_commands='add cache checkout commit config destroy diff fetch get-url get g _dvc_options='-h --help -V --version' _dvc_global_options='-h --help -q --quiet -v --verbose' -_dvc_add='-R --recursive -f --file --no-commit $(compgen -G \*)' +_dvc_add='-R --recursive -f --file --no-commit $(compgen -f)' _dvc_cache='dir' _dvc_cache_dir=' --global --system --local -u --unset' _dvc_checkout='-d --with-deps -R --recursive -f --force --relink $(compgen -G \*.dvc)' @@ -31,15 +31,15 @@ _dvc_import_url='-f --file' _dvc_import='-o --out --rev' _dvc_init='--no-scm -f --force' _dvc_install='' -_dvc_list='-R --recursive --outs-only --rev $(compgen -G \*)' _dvc_lock='$(compgen -G \*.dvc)' +_dvc_list='-R --recursive --outs-only --rev $(compgen -f)' _dvc_metrics='add modify rmeove show' -_dvc_metrics_add='-t --type -x --xpath $(compgen -G \*)' -_dvc_metrics_show='$(-t --type -x --xpath -a --all-branches -T --all-tags -R --recursive $(compgen -G \*)' +_dvc_metrics_add='-t --type -x --xpath $(compgen -f)' +_dvc_metrics_show='$(-t --type -x --xpath -a --all-branches -T --all-tags -R --recursive $(compgen -f)' _dvc_metrics_diff='--targets -t --type -x --xpath -R --show-json' -_dvc_metrics_modify='-t --type -x --xpath $(compgen -G \*)' -_dvc_metrics_remove='$(compgen -G \*)' -_dvc_move='$(compgen -G \*)' +_dvc_metrics_modify='-t --type -x --xpath $(compgen -f)' +_dvc_metrics_remove='$(compgen -f)' +_dvc_move='$(compgen -f)' _dvc_pipeline='list show' _dvc_pipeline_list='' _dvc_pipeline_show='-c --commands -o --outs --ascii --dot --tree -l --locked $(compgen -G \*.dvc)' @@ -57,8 +57,8 @@ _dvc_root='' _dvc_run='--no-exec -f --file -c --cwd -d --deps -o --outs -O --outs-no-cache --outs-persist --outs-persist-no-cache -m --metrics -M --metrics-no-cache -y --yes --overwrite-dvcfile --ignore-build-cache --remove-outs --no-commit -w --wdir' _dvc_status='-j --jobs -r --remote -a --all-branches -T --all-tags -d --with-deps -c --cloud $(compgen -G \*.dvc)' _dvc_unlock='$(compgen -G \*.dvc)' -_dvc_unprotect='$(compgen -G \*)' _dvc_update='--rev $(compgen -G \*.dvc)' +_dvc_unprotect='$(compgen -f)' _dvc_version='' # Params From 13c3b75c1cd5a4970abb74bb78c0351998a90900 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 18 Feb 2020 23:30:48 +0000 Subject: [PATCH 4/5] complete: bash: DVC-files --- scripts/completion/dvc.bash | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/scripts/completion/dvc.bash b/scripts/completion/dvc.bash index 9a5e28baf1..5f23a083c0 100644 --- a/scripts/completion/dvc.bash +++ b/scripts/completion/dvc.bash @@ -18,12 +18,12 @@ _dvc_global_options='-h --help -q --quiet -v --verbose' _dvc_add='-R --recursive -f --file --no-commit $(compgen -f)' _dvc_cache='dir' _dvc_cache_dir=' --global --system --local -u --unset' -_dvc_checkout='-d --with-deps -R --recursive -f --force --relink $(compgen -G \*.dvc)' -_dvc_commit='-f --force -d --with-deps -R --recursive $(compgen -G \*.dvc)' +_dvc_checkout='-d --with-deps -R --recursive -f --force --relink $(compgen -f -X \!*?.dvc)' +_dvc_commit='-f --force -d --with-deps -R --recursive $(compgen -f -X \!*?.dvc)' _dvc_config='-u --unset --local --system --global' _dvc_destroy='-f --force' _dvc_diff='-t --show-json --checksums' -_dvc_fetch='-j --jobs -r --remote -a --all-branches -T --all-tags -d --with-deps -R --recursive $(compgen -G \*.dvc)' +_dvc_fetch='-j --jobs -r --remote -a --all-branches -T --all-tags -d --with-deps -R --recursive $(compgen -f -X \!*?.dvc)' _dvc_get_url='' _dvc_get='-o --out --rev --show-url' _dvc_gc='-a --all-branches -T --all-tags -c --cloud -r --remote -f --force -p --projects -j --jobs' @@ -31,8 +31,8 @@ _dvc_import_url='-f --file' _dvc_import='-o --out --rev' _dvc_init='--no-scm -f --force' _dvc_install='' -_dvc_lock='$(compgen -G \*.dvc)' _dvc_list='-R --recursive --outs-only --rev $(compgen -f)' +_dvc_lock='$(compgen -f -X \!*?.dvc)' _dvc_metrics='add modify rmeove show' _dvc_metrics_add='-t --type -x --xpath $(compgen -f)' _dvc_metrics_show='$(-t --type -x --xpath -a --all-branches -T --all-tags -R --recursive $(compgen -f)' @@ -42,23 +42,23 @@ _dvc_metrics_remove='$(compgen -f)' _dvc_move='$(compgen -f)' _dvc_pipeline='list show' _dvc_pipeline_list='' -_dvc_pipeline_show='-c --commands -o --outs --ascii --dot --tree -l --locked $(compgen -G \*.dvc)' -_dvc_pull='-j --jobs -r --remote -a --all-branches -T --all-tags -f --force -d --with-deps -R --recursive $(compgen -G \*.dvc)' -_dvc_push='-j --jobs -r --remote -a --all-branches -T --all-tags -d --with-deps -R --recursive $(compgen -G \*.dvc)' +_dvc_pipeline_show='-c --commands -o --outs --ascii --dot --tree -l --locked $(compgen -f -X \!*?.dvc)' +_dvc_pull='-j --jobs -r --remote -a --all-branches -T --all-tags -f --force -d --with-deps -R --recursive $(compgen -f -X \!*?.dvc)' +_dvc_push='-j --jobs -r --remote -a --all-branches -T --all-tags -d --with-deps -R --recursive $(compgen -f -X \!*?.dvc)' _dvc_remote='add default list modify remove' _dvc_remote_add='--global --system --local -d --default -f --force' _dvc_remote_default='--global --system --local -u --unset' _dvc_remote_list='--global --system --local' _dvc_remote_modify='--global --system --local -u --unset' _dvc_remote_remove='--global --system --local' -_dvc_remove='-o --outs -p --purge -f --force $(compgen -G \*.dvc)' -_dvc_repro='-f --force -s --single-item -c --cwd -m --metrics --dry -i --interactive -p --pipeline -P --all-pipelines --ignore-build-cache --no-commit -R --recursive --downstream $(compgen -G \*.dvc)' +_dvc_remove='-o --outs -p --purge -f --force $(compgen -f -X \!*?.dvc)' +_dvc_repro='-f --force -s --single-item -c --cwd -m --metrics --dry -i --interactive -p --pipeline -P --all-pipelines --ignore-build-cache --no-commit -R --recursive --downstream $(compgen -f -X \!*?.dvc)' _dvc_root='' _dvc_run='--no-exec -f --file -c --cwd -d --deps -o --outs -O --outs-no-cache --outs-persist --outs-persist-no-cache -m --metrics -M --metrics-no-cache -y --yes --overwrite-dvcfile --ignore-build-cache --remove-outs --no-commit -w --wdir' -_dvc_status='-j --jobs -r --remote -a --all-branches -T --all-tags -d --with-deps -c --cloud $(compgen -G \*.dvc)' -_dvc_unlock='$(compgen -G \*.dvc)' -_dvc_update='--rev $(compgen -G \*.dvc)' +_dvc_status='-j --jobs -r --remote -a --all-branches -T --all-tags -d --with-deps -c --cloud $(compgen -f -X \!*?.dvc)' +_dvc_unlock='$(compgen -f -X \!*?.dvc)' _dvc_unprotect='$(compgen -f)' +_dvc_update='--rev $(compgen -f -X \!*?.dvc)' _dvc_version='' # Params From 33cc20bb10f0a65c5736ecc3211e15276cb86983 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 18 Feb 2020 23:31:17 +0000 Subject: [PATCH 5/5] complete: bash: safer and quicker opts --- scripts/completion/dvc.bash | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/completion/dvc.bash b/scripts/completion/dvc.bash index 5f23a083c0..8d3918b679 100644 --- a/scripts/completion/dvc.bash +++ b/scripts/completion/dvc.bash @@ -80,10 +80,11 @@ _dvc_comp_command() { # $1 - COMP_WORDS[2] _dvc_comp_subcommand() { local options_list="_dvc_$(_dvc_replace_hyphen $1)_$(_dvc_replace_hyphen $2)" - if [ -z "${!options_list}" ]; then + local _dvc_opts="${!options_list}" + if [ -z "$_dvc_opts" ]; then _dvc_comp_command $1 else - COMPREPLY=( $(compgen -W "$_dvc_global_options ${!options_list}" -- "$word") ) + COMPREPLY=( $(compgen -W "$_dvc_global_options $_dvc_opts" -- "$word") ) fi }