aboutsummaryrefslogtreecommitdiff
path: root/contrib/completion
diff options
context:
space:
mode:
authorDennis Stosberg <dennis@stosberg.net>2006-10-28 14:12:20 +0200
committerJunio C Hamano <junkio@cox.net>2006-10-28 13:36:39 -0700
commit367dce2a5b80da055a0d776fe830e6f19b81bd1d (patch)
tree7635e0735cb5b4942e9e1a65fdda554ddacb06a6 /contrib/completion
parent887a612fef942dd3e7dae452e2dc582738b0fb41 (diff)
downloadgit-367dce2a5b80da055a0d776fe830e6f19b81bd1d.tar.gz
git-367dce2a5b80da055a0d776fe830e6f19b81bd1d.tar.xz
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>
Diffstat (limited to 'contrib/completion')
-rwxr-xr-xcontrib/completion/git-completion.bash29
1 files changed, 27 insertions, 2 deletions
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index d9cb17d0b..b074f4fe5 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -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]}"
@@ -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 ;;