|
3 | 3 | _git_elegant() { |
4 | 4 | COMPREPLY=() |
5 | 5 | local cursor="${COMP_WORDS[COMP_CWORD]}" |
6 | | - |
| 6 | + local geops="--help --version --no-workflows" |
| 7 | + local gecops="--help --no-workflows" |
| 8 | + local offset=0 |
| 9 | + if [[ ${COMP_WORDS[*]} =~ (--no-workflows)|(-nw) ]]; then |
| 10 | + geops="" |
| 11 | + gecops="" |
| 12 | + if [[ ${COMP_WORDS[COMP_CWORD-1]} =~ (--no-workflows)|(-nw) ]]; then |
| 13 | + offset=1 |
| 14 | + fi |
| 15 | + fi |
7 | 16 | # the first word prior to the ${cursor} |
8 | | - case ""${COMP_WORDS[COMP_CWORD-1]}"" in |
9 | | - elegant|git-elegant) |
10 | | - local opts=($(git elegant commands)) |
11 | | - COMPREPLY=( $(compgen -W "${opts[*]}" -- ${cursor}) ) |
12 | | - return 0 ;; |
13 | | - accept-work|obtain-work) |
14 | | - COMPREPLY=( |
15 | | - $(compgen -W "$(git branch --remotes --list)" -- ${cursor}) |
16 | | - ) |
17 | | - return 0 ;; |
18 | | - show-release-notes) |
19 | | - COMPREPLY=( $(compgen -W "simple smart" ${cursor}) ) |
20 | | - return 0 ;; |
21 | | - *) ;; |
22 | | - esac |
| 17 | + if [[ ${#COMP_WORDS[*]} > $(( 1 + ${offset} )) ]]; then |
| 18 | + case "${COMP_WORDS[COMP_CWORD-$(( 1 + ${offset} ))]}" in |
| 19 | + elegant|git-elegant) |
| 20 | + local opts=( |
| 21 | + ${geops} |
| 22 | + $(git elegant commands) |
| 23 | + ) |
| 24 | + COMPREPLY=( $(compgen -W "${opts[*]}" -- ${cursor}) ) |
| 25 | + return 0 ;; |
| 26 | + accept-work|obtain-work) |
| 27 | + local opts=( |
| 28 | + ${gecops} |
| 29 | + $(git branch --remotes --list) |
| 30 | + ) |
| 31 | + COMPREPLY=( |
| 32 | + $(compgen -W "${opts[*]}" -- ${cursor}) |
| 33 | + ) |
| 34 | + return 0 ;; |
| 35 | + show-release-notes) |
| 36 | + COMPREPLY=( $(compgen -W "simple smart ${gecops[*]}" -- ${cursor}) ) |
| 37 | + return 0 ;; |
| 38 | + *) ;; |
| 39 | + esac |
| 40 | + fi |
23 | 41 |
|
24 | 42 | # the second word prior to the ${cursor} |
25 | | - case "${COMP_WORDS[COMP_CWORD-2]}" in |
26 | | - show-release-notes) |
27 | | - local opts=($(git for-each-ref --sort "-version:refname" --format "%(refname:short)" refs/**)) |
28 | | - COMPREPLY=( $(compgen -W "${opts[*]}" -- ${cursor}) ) |
29 | | - return 0 ;; |
30 | | - *) ;; |
31 | | - esac |
| 43 | + if [[ ${#COMP_WORDS[*]} > $(( 2 + ${offset} )) ]]; then |
| 44 | + case "${COMP_WORDS[COMP_CWORD-$(( 2 + ${offset} ))]}" in |
| 45 | + show-release-notes) |
| 46 | + local opts=($(git for-each-ref --sort "-version:refname" --format "%(refname:short)" refs/**)) |
| 47 | + COMPREPLY=( $(compgen -W "${opts[*]}" -- ${cursor}) ) |
| 48 | + return 0 ;; |
| 49 | + *) ;; |
| 50 | + esac |
| 51 | + fi |
32 | 52 |
|
33 | 53 | # the third word prior to the ${cursor} |
34 | | - case "${COMP_WORDS[COMP_CWORD-3]}" in |
35 | | - show-release-notes) |
36 | | - local opts=($(git for-each-ref --sort "-version:refname" --format "%(refname:short)" refs/**)) |
37 | | - COMPREPLY=( $(compgen -W "${opts[*]}" -- ${cursor}) ) |
38 | | - return 0 ;; |
39 | | - *) ;; |
40 | | - esac |
| 54 | + if [[ ${#COMP_WORDS[*]} > $(( 3 + ${offset} )) ]]; then |
| 55 | + case "${COMP_WORDS[COMP_CWORD-$(( 3 + ${offset} ))]}" in |
| 56 | + show-release-notes) |
| 57 | + local opts=($(git for-each-ref --sort "-version:refname" --format "%(refname:short)" refs/**)) |
| 58 | + COMPREPLY=( $(compgen -W "${opts[*]}" -- ${cursor}) ) |
| 59 | + return 0 ;; |
| 60 | + *) ;; |
| 61 | + esac |
| 62 | + fi |
41 | 63 | } |
42 | 64 |
|
43 | 65 | complete -F _git_elegant git-elegant |
0 commit comments