Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

completion: bash: allow multi-arg completion, minor tidy #3367

Merged
merged 1 commit into from
Feb 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions scripts/completion/dvc.bash
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
#!/usr/bin/env bash

#----------------------------------------------------------
# Repository: https://github.com/iterative/dvc
#
# References:
# - https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html
# - https://opensource.com/article/18/3/creating-bash-completion-script
#----------------------------------------------------------

_dvc_commands='add cache checkout commit config destroy diff fetch get-url get gc \
import-url import init install lock list metrics move pipeline pull push \
Expand Down Expand Up @@ -89,17 +84,12 @@ _dvc_comp_subcommand() {
}

# Notes:
#
# `COMPREPLY` contains what will be rendered after completion is triggered
#
# `word` refers to the current typed word
#
# `${!var}` is to evaluate the content of `var` and expand its content as a variable
#
# hello="world"
# x="hello"
# ${!x} -> ${hello} -> "world"
#
_dvc() {
local word="${COMP_WORDS[COMP_CWORD]}"

Expand All @@ -112,7 +102,7 @@ _dvc() {
esac
elif [ "${COMP_CWORD}" -eq 2 ]; then
_dvc_comp_command ${COMP_WORDS[1]}
elif [ "${COMP_CWORD}" -eq 3 ]; then
elif [ "${COMP_CWORD}" -ge 3 ]; then
_dvc_comp_subcommand ${COMP_WORDS[1]} ${COMP_WORDS[2]}
fi

Expand Down