diff options
author | Mike Frysinger <vapier@google.com> | 2021-07-26 15:30:10 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2021-07-27 06:20:52 +0000 |
commit | cfa00d6e3d6825cbe4390fbaaf5980cd6b1be77e (patch) | |
tree | 6097adb5c45a6c8ba57123d82abd76f6c63c5b1b | |
parent | 5467185db0fe31558dbb57f08135c316861a86b1 (diff) | |
download | git-repo-cfa00d6e3d6825cbe4390fbaaf5980cd6b1be77e.tar.gz |
bash-completion: complete projects with repo forall
We need to add a little bit more logic here so we stop completing
projects once we see the -c argument.
Bug: https://crbug.com/gerrit/14797
Change-Id: Ic2ba4f3dd616ec49d8ad754ff62d0d6e0250dbe6
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/312905
Reviewed-by: Xin Li <delphij@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
-rw-r--r-- | completion.bash | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/completion.bash b/completion.bash index 6a5bfe1c..09291d5c 100644 --- a/completion.bash +++ b/completion.bash | |||
@@ -14,6 +14,9 @@ | |||
14 | 14 | ||
15 | # Programmable bash completion. https://github.com/scop/bash-completion | 15 | # Programmable bash completion. https://github.com/scop/bash-completion |
16 | 16 | ||
17 | # TODO: Handle interspersed options. We handle `repo h<tab>`, but not | ||
18 | # `repo --time h<tab>`. | ||
19 | |||
17 | # Complete the list of repo subcommands. | 20 | # Complete the list of repo subcommands. |
18 | __complete_repo_list_commands() { | 21 | __complete_repo_list_commands() { |
19 | local repo=${COMP_WORDS[0]} | 22 | local repo=${COMP_WORDS[0]} |
@@ -79,6 +82,23 @@ __complete_repo_command_help() { | |||
79 | fi | 82 | fi |
80 | } | 83 | } |
81 | 84 | ||
85 | # Complete `repo forall`. | ||
86 | __complete_repo_command_forall() { | ||
87 | local current=$1 | ||
88 | # CWORD=1 is "forall". | ||
89 | # CWORD=2+ are <projects> *until* we hit the -c option. | ||
90 | local i | ||
91 | for (( i = 0; i < COMP_CWORD; ++i )); do | ||
92 | if [[ "${COMP_WORDS[i]}" == "-c" ]]; then | ||
93 | return 0 | ||
94 | fi | ||
95 | done | ||
96 | |||
97 | COMPREPLY=( | ||
98 | $(compgen -W "$(__complete_repo_list_projects)" -- "${current}") | ||
99 | ) | ||
100 | } | ||
101 | |||
82 | # Complete `repo start`. | 102 | # Complete `repo start`. |
83 | __complete_repo_command_start() { | 103 | __complete_repo_command_start() { |
84 | local current=$1 | 104 | local current=$1 |
@@ -112,7 +132,7 @@ __complete_repo_arg() { | |||
112 | return 0 | 132 | return 0 |
113 | ;; | 133 | ;; |
114 | 134 | ||
115 | help|start) | 135 | help|start|forall) |
116 | __complete_repo_command_${command} "${current}" | 136 | __complete_repo_command_${command} "${current}" |
117 | return 0 | 137 | return 0 |
118 | ;; | 138 | ;; |