##// END OF EJS Templates
teach bash_completion about --cwd
Alexis S. L. Carvalho -
r1151:10b4f2a5 default
parent child Browse files
Show More
@@ -56,19 +56,22 b''
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
@@ -80,10 +83,17 b''
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
General Comments 0
You need to be logged in to leave comments. Login now