Skip to content

Commit

Permalink
Bash completion support for aliases
Browse files Browse the repository at this point in the history
 - 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>
  • Loading branch information
Dennis Stosberg authored and Junio C Hamano committed Oct 28, 2006
1 parent 887a612 commit 367dce2
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions contrib/completion/git-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ __git_complete_file ()
esac
}

__git_aliases ()
{
git repo-config --list | grep '^alias\.' \
| sed -e 's/^alias\.//' -e 's/=.*$//'
}

__git_aliased_command ()
{
local cmdline=$(git repo-config alias.$1)
for word in $cmdline; do
if [ "${word##-*}" ]; then
echo $word
return
fi
done
}

_git_branch ()
{
local cur="${COMP_WORDS[COMP_CWORD]}"
Expand Down Expand Up @@ -264,10 +281,18 @@ _git ()
{
if [ $COMP_CWORD = 1 ]; then
COMPREPLY=($(compgen \
-W "--version $(git help -a|egrep '^ ')" \
-W "--version $(git help -a|egrep '^ ') \
$(__git_aliases)" \
-- "${COMP_WORDS[COMP_CWORD]}"))
else
case "${COMP_WORDS[1]}" in
local command="${COMP_WORDS[1]}"
local expansion=$(__git_aliased_command "$command")

if [ "$expansion" ]; then
command="$expansion"
fi

case "$command" in
branch) _git_branch ;;
cat-file) _git_cat_file ;;
checkout) _git_checkout ;;
Expand Down

0 comments on commit 367dce2

Please sign in to comment.