@matheusbsbs / matheus-bagliano / commits / 367dce2a5b
Fork 0

Bash completion support for aliases

- Add aliases to the list of available git commands. - Make completion work for aliased commands. Signed-off-by: Dennis Stosberg <dennis@stosberg.net> Signed-off-by: Junio C Hamano <junkio@cox.net>

Dennis Stosberg committed Oct 28, 2006 at 14:12 UTC 367dce2a5b80da055a0d776fe830e6f19b81bd1d
1 file changed +27 -2
contrib/completion/git-completion.bash
+27 -2
@@ -101,6 +101,23 @@ __git_complete_file ()
101 esac
102 }
103
104 +__git_aliases ()
105 +{
106 + git repo-config --list | grep '^alias\.' \
107 + | sed -e 's/^alias\.//' -e 's/=.*$//'
108 +}
109 +
110 +__git_aliased_command ()
111 +{
112 + local cmdline=$(git repo-config alias.$1)
113 + for word in $cmdline; do
114 + if [ "${word##-*}" ]; then
115 + echo $word
116 + return
117 + fi
118 + done
119 +}
120 +
121 _git_branch ()
122 {
123 local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -264,10 +281,18 @@ _git ()
281 {
282 if [ $COMP_CWORD = 1 ]; then
283 COMPREPLY=($(compgen \
267 - -W "--version $(git help -a|egrep '^ ')" \
284 + -W "--version $(git help -a|egrep '^ ') \
285 + $(__git_aliases)" \
286 -- "${COMP_WORDS[COMP_CWORD]}"))
287 else
270 - case "${COMP_WORDS[1]}" in
288 + local command="${COMP_WORDS[1]}"
289 + local expansion=$(__git_aliased_command "$command")
290 +
291 + if [ "$expansion" ]; then
292 + command="$expansion"
293 + fi
294 +
295 + case "$command" in
296 branch) _git_branch ;;
297 cat-file) _git_cat_file ;;
298 checkout) _git_checkout ;;