bash: Support unique completion on git-config.
In many cases we know a completion will be unique, but we've disabled bash's automatic space addition (-o nospace) so we need to do it ourselves when necessary. This change adds additional support for new configuration options added in 1.5.0, as well as some extended completion support for the color.* family of options. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Shawn O. Pearce committed
Feb 4, 2007 at 02:38 UTC
78d4d6a2815f20607336fcb238ba23efc00e1b0a
1 file changed
+82
-38
contrib/completion/git-completion.bash
+82
-38
@@ -64,14 +64,19 @@ __git_ps1 ()
64
__gitcomp ()
65
{
66
local all c s=$'\n' IFS=' '$'\t'$'\n'
67
+ local cur="${COMP_WORDS[COMP_CWORD]}"
68
+ if [ -n "$2" ]; then
69
+ cur="$3"
70
+ fi
71
for c in $1; do
68
- case "$c" in
69
- --*=*) all="$all$c$s" ;;
70
- *) all="$all$c $s" ;;
72
+ case "$c$4" in
73
+ --*=*) all="$all$c$4$s" ;;
74
+ *.) all="$all$c$4$s" ;;
75
+ *) all="$all$c$4 $s" ;;
76
esac
77
done
78
IFS=$s
74
- COMPREPLY=($(compgen -W "$all" -- "${COMP_WORDS[COMP_CWORD]}"))
79
+ COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
80
return
81
}
82
@@ -666,26 +671,40 @@ _git_config ()
671
local prv="${COMP_WORDS[COMP_CWORD-1]}"
672
case "$prv" in
673
branch.*.remote)
669
- COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
674
+ __gitcomp "$(__git_remotes)"
675
return
676
;;
677
branch.*.merge)
673
- COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
678
+ __gitcomp "$(__git_refs)"
679
return
680
;;
681
remote.*.fetch)
682
local remote="${prv#remote.}"
683
remote="${remote%.fetch}"
679
- COMPREPLY=($(compgen -W "$(__git_refs_remotes "$remote")" \
680
- -- "$cur"))
684
+ __gitcomp "$(__git_refs_remotes "$remote")"
685
return
686
;;
687
remote.*.push)
688
local remote="${prv#remote.}"
689
remote="${remote%.push}"
686
- COMPREPLY=($(compgen -W "$(git --git-dir="$(__gitdir)" \
690
+ __gitcomp "$(git --git-dir="$(__gitdir)" \
691
for-each-ref --format='%(refname):%(refname)' \
688
- refs/heads)" -- "$cur"))
692
+ refs/heads)"
693
+ return
694
+ ;;
695
+ pull.twohead|pull.octopus)
696
+ __gitcomp "$(__git_merge_strategies)"
697
+ return
698
+ ;;
699
+ color.branch|color.diff|color.status)
700
+ __gitcomp "always never auto"
701
+ return
702
+ ;;
703
+ color.*.*)
704
+ __gitcomp "
705
+ black red green yellow blue magenta cyan white
706
+ bold dim ul blink reverse
707
+ "
708
return
709
;;
710
*.*)
@@ -695,41 +714,39 @@ _git_config ()
714
esac
715
case "$cur" in
716
--*)
698
- COMPREPLY=($(compgen -W "
717
+ __gitcomp "
718
--global --list --replace-all
719
--get --get-all --get-regexp
720
--unset --unset-all
702
- " -- "$cur"))
721
+ "
722
return
723
;;
724
branch.*.*)
725
local pfx="${cur%.*}."
726
cur="${cur##*.}"
708
- COMPREPLY=($(compgen -P "$pfx" -W "remote merge" -- "$cur"))
727
+ __gitcomp "remote merge" "$pfx" "$cur"
728
return
729
;;
730
branch.*)
731
local pfx="${cur%.*}."
732
cur="${cur#*.}"
714
- COMPREPLY=($(compgen -P "$pfx" -S . \
715
- -W "$(__git_heads)" -- "$cur"))
733
+ __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
734
return
735
;;
736
remote.*.*)
737
local pfx="${cur%.*}."
738
cur="${cur##*.}"
721
- COMPREPLY=($(compgen -P "$pfx" -W "url fetch push" -- "$cur"))
739
+ __gitcomp "url fetch push" "$pfx" "$cur"
740
return
741
;;
742
remote.*)
743
local pfx="${cur%.*}."
744
cur="${cur#*.}"
727
- COMPREPLY=($(compgen -P "$pfx" -S . \
728
- -W "$(__git_remotes)" -- "$cur"))
745
+ __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
746
return
747
;;
748
esac
732
- COMPREPLY=($(compgen -W "
749
+ __gitcomp "
750
apply.whitespace
751
core.fileMode
752
core.gitProxy
@@ -741,40 +758,67 @@ _git_config ()
758
core.warnAmbiguousRefs
759
core.compression
760
core.legacyHeaders
744
- i18n.commitEncoding
745
- i18n.logOutputEncoding
746
- diff.color
761
+ core.packedGitWindowSize
762
+ core.packedGitLimit
763
+ color.branch
764
+ color.branch.current
765
+ color.branch.local
766
+ color.branch.remote
767
+ color.branch.plain
768
color.diff
748
- diff.renameLimit
749
- diff.renames
750
- pager.color
769
+ color.diff.plain
770
+ color.diff.meta
771
+ color.diff.frag
772
+ color.diff.old
773
+ color.diff.new
774
+ color.diff.commit
775
+ color.diff.whitespace
776
color.pager
752
- status.color
777
color.status
754
- log.showroot
755
- show.difftree
756
- showbranch.default
757
- whatchanged.difftree
778
+ color.status.header
779
+ color.status.added
780
+ color.status.changed
781
+ color.status.untracked
782
+ diff.renameLimit
783
+ diff.renames
784
+ fetch.unpackLimit
785
+ format.headers
786
+ gitcvs.enabled
787
+ gitcvs.logfile
788
+ gc.reflogexpire
789
+ gc.reflogexpireunreachable
790
+ gc.rerereresolved
791
+ gc.rerereunresolved
792
http.sslVerify
793
http.sslCert
794
http.sslKey
795
http.sslCAInfo
796
http.sslCAPath
797
http.maxRequests
764
- http.lowSpeedLimit http.lowSpeedTime
798
+ http.lowSpeedLimit
799
+ http.lowSpeedTime
800
http.noEPSV
801
+ i18n.commitEncoding
802
+ i18n.logOutputEncoding
803
+ log.showroot
804
+ merge.summary
805
+ merge.verbosity
806
pack.window
807
+ pull.octopus
808
+ pull.twohead
809
repack.useDeltaBaseOffset
768
- pull.octopus pull.twohead
769
- merge.summary
810
+ show.difftree
811
+ showbranch.default
812
+ tar.umask
813
+ transfer.unpackLimit
814
receive.unpackLimit
815
receive.denyNonFastForwards
772
- user.name user.email
773
- tar.umask
774
- gitcvs.enabled
775
- gitcvs.logfile
816
+ user.name
817
+ user.email
818
+ user.signingkey
819
+ whatchanged.difftree
820
branch. remote.
777
- " -- "$cur"))
821
+ "
822
}
823
824
_git_reset ()