Skip to content

Commit 15bf052

Browse files
committed
Merge branch 'sg/bash-completion'
* sg/bash-completion: bash: completion for gitk aliases bash: support user-supplied completion scripts for aliases bash: support user-supplied completion scripts for user's git commands bash: improve aliased command recognition
2 parents 8b5fe8c + 6672950 commit 15bf052

File tree

1 file changed

+34
-60
lines changed

1 file changed

+34
-60
lines changed

contrib/completion/git-completion.bash

Lines changed: 34 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -627,10 +627,19 @@ __git_aliased_command ()
627627
local word cmdline=$(git --git-dir="$(__gitdir)" \
628628
config --get "alias.$1")
629629
for word in $cmdline; do
630-
if [ "${word##-*}" ]; then
631-
echo $word
630+
case "$word" in
631+
\!gitk|gitk)
632+
echo "gitk"
632633
return
633-
fi
634+
;;
635+
\!*) : shell command alias ;;
636+
-*) : option ;;
637+
*=*) : setting env ;;
638+
git) : git itself ;;
639+
*)
640+
echo "$word"
641+
return
642+
esac
634643
done
635644
}
636645

@@ -1084,6 +1093,11 @@ _git_gc ()
10841093
COMPREPLY=()
10851094
}
10861095

1096+
_git_gitk ()
1097+
{
1098+
_gitk
1099+
}
1100+
10871101
_git_grep ()
10881102
{
10891103
__git_has_doubledash && return
@@ -1436,6 +1450,11 @@ _git_send_email ()
14361450
COMPREPLY=()
14371451
}
14381452

1453+
_git_stage ()
1454+
{
1455+
_git_add
1456+
}
1457+
14391458
__git_config_get_set_variables ()
14401459
{
14411460
local prevword word config_file= c=$COMP_CWORD
@@ -2167,6 +2186,11 @@ _git_tag ()
21672186
esac
21682187
}
21692188

2189+
_git_whatchanged ()
2190+
{
2191+
_git_log
2192+
}
2193+
21702194
_git ()
21712195
{
21722196
local i c=1 command __git_dir
@@ -2203,64 +2227,14 @@ _git ()
22032227
return
22042228
fi
22052229

2230+
local completion_func="_git_${command//-/_}"
2231+
declare -F $completion_func >/dev/null && $completion_func && return
2232+
22062233
local expansion=$(__git_aliased_command "$command")
2207-
[ "$expansion" ] && command="$expansion"
2208-
2209-
case "$command" in
2210-
am) _git_am ;;
2211-
add) _git_add ;;
2212-
apply) _git_apply ;;
2213-
archive) _git_archive ;;
2214-
bisect) _git_bisect ;;
2215-
bundle) _git_bundle ;;
2216-
branch) _git_branch ;;
2217-
checkout) _git_checkout ;;
2218-
cherry) _git_cherry ;;
2219-
cherry-pick) _git_cherry_pick ;;
2220-
clean) _git_clean ;;
2221-
clone) _git_clone ;;
2222-
commit) _git_commit ;;
2223-
config) _git_config ;;
2224-
describe) _git_describe ;;
2225-
diff) _git_diff ;;
2226-
difftool) _git_difftool ;;
2227-
fetch) _git_fetch ;;
2228-
format-patch) _git_format_patch ;;
2229-
fsck) _git_fsck ;;
2230-
gc) _git_gc ;;
2231-
grep) _git_grep ;;
2232-
help) _git_help ;;
2233-
init) _git_init ;;
2234-
log) _git_log ;;
2235-
ls-files) _git_ls_files ;;
2236-
ls-remote) _git_ls_remote ;;
2237-
ls-tree) _git_ls_tree ;;
2238-
merge) _git_merge;;
2239-
mergetool) _git_mergetool;;
2240-
merge-base) _git_merge_base ;;
2241-
mv) _git_mv ;;
2242-
name-rev) _git_name_rev ;;
2243-
notes) _git_notes ;;
2244-
pull) _git_pull ;;
2245-
push) _git_push ;;
2246-
rebase) _git_rebase ;;
2247-
remote) _git_remote ;;
2248-
replace) _git_replace ;;
2249-
reset) _git_reset ;;
2250-
revert) _git_revert ;;
2251-
rm) _git_rm ;;
2252-
send-email) _git_send_email ;;
2253-
shortlog) _git_shortlog ;;
2254-
show) _git_show ;;
2255-
show-branch) _git_show_branch ;;
2256-
stash) _git_stash ;;
2257-
stage) _git_add ;;
2258-
submodule) _git_submodule ;;
2259-
svn) _git_svn ;;
2260-
tag) _git_tag ;;
2261-
whatchanged) _git_log ;;
2262-
*) COMPREPLY=() ;;
2263-
esac
2234+
if [ -n "$expansion" ]; then
2235+
completion_func="_git_${expansion//-/_}"
2236+
declare -F $completion_func >/dev/null && $completion_func
2237+
fi
22642238
}
22652239

22662240
_gitk ()

0 commit comments

Comments
 (0)