File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 21
21
# source ~/.git-completion.sh
22
22
# 3) Consider changing your PS1 to also show the current branch,
23
23
# see git-prompt.sh for details.
24
+ #
25
+ # If you use complex aliases of form '!f() { ... }; f', you can use the null
26
+ # command ':' as the first command in the function body to declare the desired
27
+ # completion style. For example '!f() { : git commit ; ... }; f' will
28
+ # tell the completion to use commit completion. This also works with aliases
29
+ # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
24
30
25
31
case " $COMP_WORDBREAKS " in
26
32
* :* ) : great ;;
@@ -781,6 +787,10 @@ __git_aliased_command ()
781
787
-* ) : option ;;
782
788
* =* ) : setting env ;;
783
789
git) : git itself ;;
790
+ \(\) ) : skip parens of shell function definition ;;
791
+ {) : skip start of shell helper function ;;
792
+ :) : skip null command ;;
793
+ \' * ) : skip opening quote after sh -c ;;
784
794
* )
785
795
echo " $word "
786
796
return
Original file line number Diff line number Diff line change @@ -550,6 +550,33 @@ test_expect_success 'complete files' '
550
550
test_completion "git add mom" "momified"
551
551
'
552
552
553
+ test_expect_success " completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
554
+ test_config alias.co "!sh -c ' " '" ' git checkout ...' " '" ' " &&
555
+ test_completion "git co m" <<-\EOF
556
+ master Z
557
+ mybranch Z
558
+ mytag Z
559
+ EOF
560
+ '
561
+
562
+ test_expect_success ' completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '
563
+ test_config alias.co "!f () { VAR=val git checkout ... ; } f" &&
564
+ test_completion "git co m" <<-\EOF
565
+ master Z
566
+ mybranch Z
567
+ mytag Z
568
+ EOF
569
+ '
570
+
571
+ test_expect_success ' completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '
572
+ test_config alias.co "!f() { : git checkout ; if ... } f" &&
573
+ test_completion "git co m" <<-\EOF
574
+ master Z
575
+ mybranch Z
576
+ mytag Z
577
+ EOF
578
+ '
579
+
553
580
test_expect_failure ' complete with tilde expansion' '
554
581
git init tmp && cd tmp &&
555
582
test_when_finished "cd .. && rm -rf tmp" &&
You can’t perform that action at this time.
0 commit comments