diff options
Diffstat (limited to 'completion.bash')
-rw-r--r-- | completion.bash | 67 |
1 files changed, 51 insertions, 16 deletions
diff --git a/completion.bash b/completion.bash index 0b52d29c..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]} |
@@ -37,6 +40,7 @@ __complete_repo_list_branches() { | |||
37 | __complete_repo_list_projects() { | 40 | __complete_repo_list_projects() { |
38 | local repo=${COMP_WORDS[0]} | 41 | local repo=${COMP_WORDS[0]} |
39 | "${repo}" list -n 2>/dev/null | 42 | "${repo}" list -n 2>/dev/null |
43 | "${repo}" list -p --relative-to=. 2>/dev/null | ||
40 | } | 44 | } |
41 | 45 | ||
42 | # Complete the repo <command> argument. | 46 | # Complete the repo <command> argument. |
@@ -66,6 +70,48 @@ __complete_repo_command_projects() { | |||
66 | COMPREPLY=($(compgen -W "$(__complete_repo_list_projects)" -- "${current}")) | 70 | COMPREPLY=($(compgen -W "$(__complete_repo_list_projects)" -- "${current}")) |
67 | } | 71 | } |
68 | 72 | ||
73 | # Complete `repo help`. | ||
74 | __complete_repo_command_help() { | ||
75 | local current=$1 | ||
76 | # CWORD=1 is "start". | ||
77 | # CWORD=2 is the <subcommand> which we complete here. | ||
78 | if [[ ${COMP_CWORD} -eq 2 ]]; then | ||
79 | COMPREPLY=( | ||
80 | $(compgen -W "$(__complete_repo_list_commands)" -- "${current}") | ||
81 | ) | ||
82 | fi | ||
83 | } | ||
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 | |||
102 | # Complete `repo start`. | ||
103 | __complete_repo_command_start() { | ||
104 | local current=$1 | ||
105 | # CWORD=1 is "start". | ||
106 | # CWORD=2 is the <branch> which we don't complete. | ||
107 | # CWORD=3+ are <projects> which we complete here. | ||
108 | if [[ ${COMP_CWORD} -gt 2 ]]; then | ||
109 | COMPREPLY=( | ||
110 | $(compgen -W "$(__complete_repo_list_projects)" -- "${current}") | ||
111 | ) | ||
112 | fi | ||
113 | } | ||
114 | |||
69 | # Complete the repo subcommand arguments. | 115 | # Complete the repo subcommand arguments. |
70 | __complete_repo_arg() { | 116 | __complete_repo_arg() { |
71 | if [[ ${COMP_CWORD} -le 1 ]]; then | 117 | if [[ ${COMP_CWORD} -le 1 ]]; then |
@@ -86,21 +132,8 @@ __complete_repo_arg() { | |||
86 | return 0 | 132 | return 0 |
87 | ;; | 133 | ;; |
88 | 134 | ||
89 | help) | 135 | help|start|forall) |
90 | if [[ ${COMP_CWORD} -eq 2 ]]; then | 136 | __complete_repo_command_${command} "${current}" |
91 | COMPREPLY=( | ||
92 | $(compgen -W "$(__complete_repo_list_commands)" -- "${current}") | ||
93 | ) | ||
94 | fi | ||
95 | return 0 | ||
96 | ;; | ||
97 | |||
98 | start) | ||
99 | if [[ ${COMP_CWORD} -gt 2 ]]; then | ||
100 | COMPREPLY=( | ||
101 | $(compgen -W "$(__complete_repo_list_projects)" -- "${current}") | ||
102 | ) | ||
103 | fi | ||
104 | return 0 | 137 | return 0 |
105 | ;; | 138 | ;; |
106 | 139 | ||
@@ -118,4 +151,6 @@ __complete_repo() { | |||
118 | return 0 | 151 | return 0 |
119 | } | 152 | } |
120 | 153 | ||
121 | complete -F __complete_repo repo | 154 | # Fallback to the default complete methods if we aren't able to provide anything |
155 | # useful. This will allow e.g. local paths to be used when it makes sense. | ||
156 | complete -F __complete_repo -o bashdefault -o default repo | ||