Mercurial > hg
comparison contrib/bash_completion @ 1587:851bc33ff545
Less annoying directory completion (see http://bugs.debian.org/343458)
The current bash completion script is quite painful in conjuntion with
deep directory trees because it adds a space after each successful
directory completion. Eg. "hg clone /ho<tab>" is completed to "hg clone
/home " when what you really want is "hg clone /home/" (assuming the
complete path to the repository looks like /home/foo/hg...).
That's because the 'complete' command does not know about the type of
completion it receives from the _hg shell function. When only a single
completion is returned, it assumes completion is complete and tells
readline to add a trailing space. This behaviour is usually wanted, but
not in the case of directory completion.
I've attached a patch that circumvents this problem by only returning
successful completions for directories that contain a .hg subdirectory.
If no repositories are found, no completions are returned either, and
bash falls back to ordinary (filename) completion. I find this behaviour
a lot less annoying than the current one.
Alternative: Use option nospace for the 'complete' command and let _hg
itself take care of adding a trailing space where appropriate. That's a
far more intrusive change, though.
author | Daniel Kobras <kobras@debian.org> |
---|---|
date | Thu, 15 Dec 2005 15:40:14 +0100 |
parents | 561b17b7d3a2 |
children | 1c75487badd6 |
comparison
equal
deleted
inserted
replaced
1586:5c5aaaa9ab6f | 1587:851bc33ff545 |
---|---|
25 | 25 |
26 _hg_paths() | 26 _hg_paths() |
27 { | 27 { |
28 local paths="$(hg paths | sed -e 's/ = .*$//')" | 28 local paths="$(hg paths | sed -e 's/ = .*$//')" |
29 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -W "$paths" -- "$cur" )) | 29 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -W "$paths" -- "$cur" )) |
30 } | |
31 | |
32 _hg_repos() | |
33 { | |
34 local i | |
35 for i in $( compgen -d -- "$cur" ); do | |
36 test ! -d "$i"/.hg || COMPREPLY=(${COMPREPLY[@]:-} "$i") | |
37 done | |
30 } | 38 } |
31 | 39 |
32 _hg_status() | 40 _hg_status() |
33 { | 41 { |
34 local files="$( hg status -$1 | cut -b 3- )" | 42 local files="$( hg status -$1 | cut -b 3- )" |
90 fi | 98 fi |
91 | 99 |
92 # global options | 100 # global options |
93 case "$prev" in | 101 case "$prev" in |
94 -R|--repository) | 102 -R|--repository) |
95 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) | 103 _hg_repos |
96 return | 104 return |
97 ;; | 105 ;; |
98 --cwd) | 106 --cwd) |
99 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) | 107 # Stick with default bash completion |
100 return | 108 return |
101 ;; | 109 ;; |
102 esac | 110 esac |
103 | 111 |
104 if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then | 112 if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then |
121 export|manifest|update) | 129 export|manifest|update) |
122 _hg_tags | 130 _hg_tags |
123 ;; | 131 ;; |
124 pull|push|outgoing|incoming) | 132 pull|push|outgoing|incoming) |
125 _hg_paths | 133 _hg_paths |
126 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) | 134 _hg_repos |
127 ;; | 135 ;; |
128 paths) | 136 paths) |
129 _hg_paths | 137 _hg_paths |
130 ;; | 138 ;; |
131 add) | 139 add) |
149 clone) | 157 clone) |
150 local count=$(_hg_count_non_option) | 158 local count=$(_hg_count_non_option) |
151 if [ $count = 1 ]; then | 159 if [ $count = 1 ]; then |
152 _hg_paths | 160 _hg_paths |
153 fi | 161 fi |
154 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) | 162 _hg_repos |
155 ;; | 163 ;; |
156 debugindex|debugindexdot) | 164 debugindex|debugindexdot) |
157 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -X "!*.i" -- "$cur" )) | 165 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -X "!*.i" -- "$cur" )) |
158 ;; | 166 ;; |
159 debugdata) | 167 debugdata) |