Mercurial > hg > mercurial-crew-with-dirclash
comparison contrib/bash_completion @ 1151:10b4f2a5ce17
teach bash_completion about --cwd
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Mon, 29 Aug 2005 20:37:07 +0200 |
parents | 4ee09418c8e5 |
children | ff560ce0c635 |
comparison
equal
deleted
inserted
replaced
1150:4ee09418c8e5 | 1151:10b4f2a5ce17 |
---|---|
54 } | 54 } |
55 | 55 |
56 _hg() | 56 _hg() |
57 { | 57 { |
58 local cur prev cmd opts i | 58 local cur prev cmd opts i |
59 # global options that receive an argument | |
60 local global_args='--cwd|-R|--repository' | |
59 | 61 |
60 COMPREPLY=() | 62 COMPREPLY=() |
61 cur="$2" | 63 cur="$2" |
62 prev="$3" | 64 prev="$3" |
63 | 65 |
64 # searching for the command | 66 # searching for the command |
65 # (first non-option argument that doesn't follow -R/--repository) | 67 # (first non-option argument that doesn't follow a global option that |
68 # receives an argument) | |
66 for (( i=1; $i<=$COMP_CWORD; i++ )); do | 69 for (( i=1; $i<=$COMP_CWORD; i++ )); do |
67 if [[ ${COMP_WORDS[i]} != -* ]] \ | 70 if [[ ${COMP_WORDS[i]} != -* ]]; then |
68 && [ "${COMP_WORDS[i-1]}" != -R ] \ | 71 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then |
69 && [ "${COMP_WORDS[i-1]}" != --repository ]; then | 72 cmd="${COMP_WORDS[i]}" |
70 cmd="${COMP_WORDS[i]}" | 73 break |
71 break | 74 fi |
72 fi | 75 fi |
73 done | 76 done |
74 | 77 |
75 if [[ "$cur" == -* ]]; then | 78 if [[ "$cur" == -* ]]; then |
76 # this assumes that there are no commands with spaces in the name | 79 # this assumes that there are no commands with spaces in the name |
78 | 81 |
79 COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$opts" -- "$cur") ) | 82 COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$opts" -- "$cur") ) |
80 return | 83 return |
81 fi | 84 fi |
82 | 85 |
83 if [ "$prev" = -R ] || [ "$prev" = --repository ]; then | 86 # global options |
84 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) | 87 case "$prev" in |
85 return | 88 -R|--repository) |
86 fi | 89 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) |
90 return | |
91 ;; | |
92 --cwd) | |
93 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) | |
94 return | |
95 ;; | |
96 esac | |
87 | 97 |
88 if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then | 98 if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then |
89 _hg_commands | 99 _hg_commands |
90 return | 100 return |
91 fi | 101 fi |