summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorFelipe Contreras <felipe.contreras@gmail.com>2020-11-09 20:03:42 -0600
committerJunio C Hamano <gitster@pobox.com>2020-11-09 18:09:21 -0800
commit9414938c348f47c76dcea7826ea0b22adb585300 (patch)
tree97284598bbf3e3350d51b0364b7c0b82e8c8ba39 /contrib
parente4d83eee9239207622e2b1cc43967da5051c189c (diff)
downloadgit-9414938c348f47c76dcea7826ea0b22adb585300.tar.gz
completion: bash: support recursive aliases
It is possible to have recursive aliases like: l = log --oneline lg = l --graph So the completion should detect such aliases as well. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib')
-rw-r--r--contrib/completion/git-completion.bash50
1 files changed, 31 insertions, 19 deletions
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 7c81e4ba49..97eccffa4a 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1120,26 +1120,38 @@ __git_pretty_aliases ()
# __git_aliased_command requires 1 argument
__git_aliased_command ()
{
- local word cmdline=$(__git config --get "alias.$1")
- for word in $cmdline; do
- case "$word" in
- \!gitk|gitk)
- echo "gitk"
- return
- ;;
- \!*) : shell command alias ;;
- -*) : option ;;
- *=*) : setting env ;;
- git) : git itself ;;
- \(\)) : skip parens of shell function definition ;;
- {) : skip start of shell helper function ;;
- :) : skip null command ;;
- \'*) : skip opening quote after sh -c ;;
- *)
- echo "$word"
- return
- esac
+ local cur=$1 last word cmdline
+
+ while [[ -n "$cur" ]]; do
+ cmdline=$(__git config --get "alias.$cur")
+ last=$cur
+ cur=
+
+ for word in $cmdline; do
+ case "$word" in
+ \!gitk|gitk)
+ cur="gitk"
+ break
+ ;;
+ \!*) : shell command alias ;;
+ -*) : option ;;
+ *=*) : setting env ;;
+ git) : git itself ;;
+ \(\)) : skip parens of shell function definition ;;
+ {) : skip start of shell helper function ;;
+ :) : skip null command ;;
+ \'*) : skip opening quote after sh -c ;;
+ *)
+ cur="$word"
+ break
+ esac
+ done
done
+
+ cur=$last
+ if [[ "$cur" != "$1" ]]; then
+ echo "$cur"
+ fi
}
# Check whether one of the given words is present on the command line,