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>
This commit is contained in:
Shawn O. Pearce 2007-02-04 02:38:37 -05:00 committed by Junio C Hamano
parent a925c6f165
commit 78d4d6a281

View File

@ -64,14 +64,19 @@ __git_ps1 ()
__gitcomp () __gitcomp ()
{ {
local all c s=$'\n' IFS=' '$'\t'$'\n' local all c s=$'\n' IFS=' '$'\t'$'\n'
local cur="${COMP_WORDS[COMP_CWORD]}"
if [ -n "$2" ]; then
cur="$3"
fi
for c in $1; do for c in $1; do
case "$c" in case "$c$4" in
--*=*) all="$all$c$s" ;; --*=*) all="$all$c$4$s" ;;
*) all="$all$c $s" ;; *.) all="$all$c$4$s" ;;
*) all="$all$c$4 $s" ;;
esac esac
done done
IFS=$s IFS=$s
COMPREPLY=($(compgen -W "$all" -- "${COMP_WORDS[COMP_CWORD]}")) COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
return return
} }
@ -666,26 +671,40 @@ _git_config ()
local prv="${COMP_WORDS[COMP_CWORD-1]}" local prv="${COMP_WORDS[COMP_CWORD-1]}"
case "$prv" in case "$prv" in
branch.*.remote) branch.*.remote)
COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur")) __gitcomp "$(__git_remotes)"
return return
;; ;;
branch.*.merge) branch.*.merge)
COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur")) __gitcomp "$(__git_refs)"
return return
;; ;;
remote.*.fetch) remote.*.fetch)
local remote="${prv#remote.}" local remote="${prv#remote.}"
remote="${remote%.fetch}" remote="${remote%.fetch}"
COMPREPLY=($(compgen -W "$(__git_refs_remotes "$remote")" \ __gitcomp "$(__git_refs_remotes "$remote")"
-- "$cur"))
return return
;; ;;
remote.*.push) remote.*.push)
local remote="${prv#remote.}" local remote="${prv#remote.}"
remote="${remote%.push}" remote="${remote%.push}"
COMPREPLY=($(compgen -W "$(git --git-dir="$(__gitdir)" \ __gitcomp "$(git --git-dir="$(__gitdir)" \
for-each-ref --format='%(refname):%(refname)' \ for-each-ref --format='%(refname):%(refname)' \
refs/heads)" -- "$cur")) refs/heads)"
return
;;
pull.twohead|pull.octopus)
__gitcomp "$(__git_merge_strategies)"
return
;;
color.branch|color.diff|color.status)
__gitcomp "always never auto"
return
;;
color.*.*)
__gitcomp "
black red green yellow blue magenta cyan white
bold dim ul blink reverse
"
return return
;; ;;
*.*) *.*)
@ -695,41 +714,39 @@ _git_config ()
esac esac
case "$cur" in case "$cur" in
--*) --*)
COMPREPLY=($(compgen -W " __gitcomp "
--global --list --replace-all --global --list --replace-all
--get --get-all --get-regexp --get --get-all --get-regexp
--unset --unset-all --unset --unset-all
" -- "$cur")) "
return return
;; ;;
branch.*.*) branch.*.*)
local pfx="${cur%.*}." local pfx="${cur%.*}."
cur="${cur##*.}" cur="${cur##*.}"
COMPREPLY=($(compgen -P "$pfx" -W "remote merge" -- "$cur")) __gitcomp "remote merge" "$pfx" "$cur"
return return
;; ;;
branch.*) branch.*)
local pfx="${cur%.*}." local pfx="${cur%.*}."
cur="${cur#*.}" cur="${cur#*.}"
COMPREPLY=($(compgen -P "$pfx" -S . \ __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
-W "$(__git_heads)" -- "$cur"))
return return
;; ;;
remote.*.*) remote.*.*)
local pfx="${cur%.*}." local pfx="${cur%.*}."
cur="${cur##*.}" cur="${cur##*.}"
COMPREPLY=($(compgen -P "$pfx" -W "url fetch push" -- "$cur")) __gitcomp "url fetch push" "$pfx" "$cur"
return return
;; ;;
remote.*) remote.*)
local pfx="${cur%.*}." local pfx="${cur%.*}."
cur="${cur#*.}" cur="${cur#*.}"
COMPREPLY=($(compgen -P "$pfx" -S . \ __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
-W "$(__git_remotes)" -- "$cur"))
return return
;; ;;
esac esac
COMPREPLY=($(compgen -W " __gitcomp "
apply.whitespace apply.whitespace
core.fileMode core.fileMode
core.gitProxy core.gitProxy
@ -741,40 +758,67 @@ _git_config ()
core.warnAmbiguousRefs core.warnAmbiguousRefs
core.compression core.compression
core.legacyHeaders core.legacyHeaders
i18n.commitEncoding core.packedGitWindowSize
i18n.logOutputEncoding core.packedGitLimit
diff.color color.branch
color.branch.current
color.branch.local
color.branch.remote
color.branch.plain
color.diff color.diff
color.diff.plain
color.diff.meta
color.diff.frag
color.diff.old
color.diff.new
color.diff.commit
color.diff.whitespace
color.pager
color.status
color.status.header
color.status.added
color.status.changed
color.status.untracked
diff.renameLimit diff.renameLimit
diff.renames diff.renames
pager.color fetch.unpackLimit
color.pager format.headers
status.color gitcvs.enabled
color.status gitcvs.logfile
log.showroot gc.reflogexpire
show.difftree gc.reflogexpireunreachable
showbranch.default gc.rerereresolved
whatchanged.difftree gc.rerereunresolved
http.sslVerify http.sslVerify
http.sslCert http.sslCert
http.sslKey http.sslKey
http.sslCAInfo http.sslCAInfo
http.sslCAPath http.sslCAPath
http.maxRequests http.maxRequests
http.lowSpeedLimit http.lowSpeedTime http.lowSpeedLimit
http.lowSpeedTime
http.noEPSV http.noEPSV
pack.window i18n.commitEncoding
repack.useDeltaBaseOffset i18n.logOutputEncoding
pull.octopus pull.twohead log.showroot
merge.summary merge.summary
merge.verbosity
pack.window
pull.octopus
pull.twohead
repack.useDeltaBaseOffset
show.difftree
showbranch.default
tar.umask
transfer.unpackLimit
receive.unpackLimit receive.unpackLimit
receive.denyNonFastForwards receive.denyNonFastForwards
user.name user.email user.name
tar.umask user.email
gitcvs.enabled user.signingkey
gitcvs.logfile whatchanged.difftree
branch. remote. branch. remote.
" -- "$cur")) "
} }
_git_reset () _git_reset ()