From 9f4cc6f76b8a15a89b85a43e0c0016a64d368709 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 4 Feb 2007 02:38:17 -0500 Subject: [PATCH 1/8] bash: Remove short option completions for branch/checkout/diff. The short options (-l, -f, -d) for git-branch are rather silly to include in the completion generation as these options must be fully typed out by the user and most users already know what the options are anyway, so including them in the suggested completions does not offer huge value. (The same goes for git-checkout and git-diff.) Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 83c69ecf48..971fefb05f 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -359,7 +359,7 @@ _git_apply () _git_branch () { local cur="${COMP_WORDS[COMP_CWORD]}" - COMPREPLY=($(compgen -W "-l -f -d -D $(__git_refs)" -- "$cur")) + COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur")) } _git_cat_file () @@ -381,7 +381,7 @@ _git_cat_file () _git_checkout () { local cur="${COMP_WORDS[COMP_CWORD]}" - COMPREPLY=($(compgen -W "-l -b $(__git_refs)" -- "$cur")) + COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur")) } _git_cherry_pick () @@ -421,7 +421,7 @@ _git_diff () _git_diff_tree () { local cur="${COMP_WORDS[COMP_CWORD]}" - COMPREPLY=($(compgen -W "-r -p -M $(__git_refs)" -- "$cur")) + COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur")) } _git_fetch () From 2e3a430a9a976ec9324b33fef41dfeb55353a1ae Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 4 Feb 2007 02:38:21 -0500 Subject: [PATCH 2/8] bash: Classify cat-file and reflog as plumbing. Now that git-show is capable of displaying any file content from any revision and is the approved Porcelain-ish level method of doing so, cat-file should no longer be classified as a user-level utility by the bash completion package. I'm also classifying the new git-reflog command as plumbing for the time being as there are no subcommands which are really useful to the end-user. git-gc already invokes `git reflog expire --all`, which makes it rather unnecessary for the user to invoke it directly. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 971fefb05f..b87f96d9ea 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1,7 +1,7 @@ # # bash completion support for core Git. # -# Copyright (C) 2006 Shawn Pearce +# Copyright (C) 2006,2007 Shawn Pearce # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/). # # The contained completion routines provide support for completing: @@ -235,6 +235,7 @@ __git_commands () for i in $(git help -a|egrep '^ ') do case $i in + cat-file) : plumbing;; check-ref-format) : plumbing;; commit-tree) : plumbing;; convert-objects) : plumbing;; @@ -258,6 +259,7 @@ __git_commands () peek-remote) : plumbing;; read-tree) : plumbing;; receive-pack) : plumbing;; + reflog) : plumbing;; rerere) : plumbing;; rev-list) : plumbing;; rev-parse) : plumbing;; @@ -362,22 +364,6 @@ _git_branch () COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur")) } -_git_cat_file () -{ - local cur="${COMP_WORDS[COMP_CWORD]}" - case "${COMP_WORDS[0]},$COMP_CWORD" in - git-cat-file*,1) - COMPREPLY=($(compgen -W "-p -t blob tree commit tag" -- "$cur")) - ;; - git,2) - COMPREPLY=($(compgen -W "-p -t blob tree commit tag" -- "$cur")) - ;; - *) - __git_complete_file - ;; - esac -} - _git_checkout () { local cur="${COMP_WORDS[COMP_CWORD]}" @@ -802,7 +788,6 @@ _git () am) _git_am ;; apply) _git_apply ;; branch) _git_branch ;; - cat-file) _git_cat_file ;; checkout) _git_checkout ;; cherry-pick) _git_cherry_pick ;; commit) _git_commit ;; @@ -840,7 +825,6 @@ complete -o default -F _gitk gitk complete -o default -F _git_am git-am complete -o default -F _git_apply git-apply complete -o default -F _git_branch git-branch -complete -o default -o nospace -F _git_cat_file git-cat-file complete -o default -F _git_checkout git-checkout complete -o default -F _git_cherry_pick git-cherry-pick complete -o default -F _git_commit git-commit @@ -871,7 +855,6 @@ if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then complete -o default -F _git_apply git-apply.exe complete -o default -o nospace -F _git git.exe complete -o default -F _git_branch git-branch.exe -complete -o default -o nospace -F _git_cat_file git-cat-file.exe complete -o default -o nospace -F _git_diff git-diff.exe complete -o default -o nospace -F _git_diff_tree git-diff-tree.exe complete -o default -o nospace -F _git_format_patch git-format-patch.exe From 8435b548480a6b6d110fd2f59b3139f25ffb392e Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 4 Feb 2007 02:38:23 -0500 Subject: [PATCH 3/8] bash: Complete long options to git-add. The new --interactive mode of git-add can be very useful, so users will probably want to have completion for it. Likewise the new git-add--interactive executable is actually a plumbing command. Its invoked by `git add --interactive` and is not intended to be invoked directly by the user. Therefore we should hide it from the list of available Git commands. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index b87f96d9ea..93f2af5e1f 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -235,6 +235,7 @@ __git_commands () for i in $(git help -a|egrep '^ ') do case $i in + add--interactive) : plumbing;; cat-file) : plumbing;; check-ref-format) : plumbing;; commit-tree) : plumbing;; @@ -358,6 +359,19 @@ _git_apply () COMPREPLY=() } +_git_add () +{ + local cur="${COMP_WORDS[COMP_CWORD]}" + case "$cur" in + --*) + COMPREPLY=($(compgen -W " + --interactive + " -- "$cur")) + return + esac + COMPREPLY=() +} + _git_branch () { local cur="${COMP_WORDS[COMP_CWORD]}" @@ -786,6 +800,7 @@ _git () case "$command" in am) _git_am ;; + add) _git_add ;; apply) _git_apply ;; branch) _git_branch ;; checkout) _git_checkout ;; @@ -852,6 +867,7 @@ complete -o default -o nospace -F _git_log git-whatchanged # included the '.exe' suffix. # if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then +complete -o default -F _git_add git-add.exe complete -o default -F _git_apply git-apply.exe complete -o default -o nospace -F _git git.exe complete -o default -F _git_branch git-branch.exe From 72e5e989b8c22dc6dd2b4f889d5d0dabf698b387 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 4 Feb 2007 02:38:27 -0500 Subject: [PATCH 4/8] bash: Add space after unique command name is completed. Because we use the nospace option for our completion function for the main 'git' wrapper bash won't automatically add a space after a unique completion has been made by the user. This has been pointed out in the past by Linus Torvalds as an undesired behavior. I agree. We have to use the nospace option to ensure path completion for a command such as `git show` works properly, but that breaks the common case of getting the space for a unique completion. So now we set IFS=$'\n' (linefeed) and add a trailing space to every possible completion option. This causes bash to insert the space when the completion is unique. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 93f2af5e1f..1cf576e1e5 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -61,6 +61,20 @@ __git_ps1 () fi } +__gitcomp () +{ + local all c s=$'\n' IFS=' '$'\t'$'\n' + for c in $1; do + case "$c" in + --*=*) all="$all$c$s" ;; + *) all="$all$c $s" ;; + esac + done + IFS=$s + COMPREPLY=($(compgen -W "$all" -- "${COMP_WORDS[COMP_CWORD]}")) + return +} + __git_heads () { local cmd i is_hash=y dir="$(__gitdir "$1")" @@ -787,12 +801,12 @@ _git () done if [ $c -eq $COMP_CWORD -a -z "$command" ]; then - COMPREPLY=($(compgen -W " - --git-dir= --version --exec-path - $(__git_commands) - $(__git_aliases) - " -- "${COMP_WORDS[COMP_CWORD]}")) - return; + case "${COMP_WORDS[COMP_CWORD]}" in + --*=*) COMPREPLY=() ;; + --*) __gitcomp "--git-dir= --bare --version --exec-path" ;; + *) __gitcomp "$(__git_commands) $(__git_aliases)" ;; + esac + return fi local expansion=$(__git_aliased_command "$command") From a925c6f165a3374ff4a69d7c991ead2d9fa90b98 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 4 Feb 2007 02:38:30 -0500 Subject: [PATCH 5/8] bash: Classify more commends out of completion. Most of these commands are not ones you want to invoke from the command line on a frequent basis, or have been renamed in 1.5.0 to more friendly versions, but the old names are being left behind to support existing scripts in the wild. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 1cf576e1e5..382c8177a3 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -250,16 +250,24 @@ __git_commands () do case $i in add--interactive) : plumbing;; + applymbox) : ask gittus;; + applypatch) : ask gittus;; + archimport) : import;; cat-file) : plumbing;; check-ref-format) : plumbing;; commit-tree) : plumbing;; convert-objects) : plumbing;; + cvsexportcommit) : export;; + cvsimport) : import;; cvsserver) : daemon;; daemon) : daemon;; + fsck-objects) : plumbing;; fetch-pack) : plumbing;; + fmt-merge-msg) : plumbing;; hash-object) : plumbing;; http-*) : transport;; index-pack) : plumbing;; + init-db) : deprecated;; local-fetch) : plumbing;; mailinfo) : plumbing;; mailsplit) : plumbing;; @@ -272,9 +280,13 @@ __git_commands () parse-remote) : plumbing;; patch-id) : plumbing;; peek-remote) : plumbing;; + prune) : plumbing;; + prune-packed) : plumbing;; + quiltimport) : import;; read-tree) : plumbing;; receive-pack) : plumbing;; reflog) : plumbing;; + repo-config) : plumbing;; rerere) : plumbing;; rev-list) : plumbing;; rev-parse) : plumbing;; @@ -285,14 +297,19 @@ __git_commands () show-index) : plumbing;; ssh-*) : transport;; stripspace) : plumbing;; + svn) : import export;; + svnimport) : import;; symbolic-ref) : plumbing;; + tar-tree) : deprecated;; unpack-file) : plumbing;; unpack-objects) : plumbing;; + update-index) : plumbing;; update-ref) : plumbing;; update-server-info) : daemon;; upload-archive) : plumbing;; upload-pack) : plumbing;; write-tree) : plumbing;; + verify-tag) : plumbing;; *) echo $i;; esac done @@ -834,7 +851,6 @@ _git () pull) _git_pull ;; push) _git_push ;; rebase) _git_rebase ;; - repo-config) _git_config ;; reset) _git_reset ;; show) _git_show ;; show-branch) _git_log ;; From 78d4d6a2815f20607336fcb238ba23efc00e1b0a Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 4 Feb 2007 02:38:37 -0500 Subject: [PATCH 6/8] 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 Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 122 +++++++++++++++++-------- 1 file changed, 83 insertions(+), 39 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 382c8177a3..38d61210a2 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -64,14 +64,19 @@ __git_ps1 () __gitcomp () { 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 - case "$c" in - --*=*) all="$all$c$s" ;; - *) all="$all$c $s" ;; + case "$c$4" in + --*=*) all="$all$c$4$s" ;; + *.) all="$all$c$4$s" ;; + *) all="$all$c$4 $s" ;; esac done IFS=$s - COMPREPLY=($(compgen -W "$all" -- "${COMP_WORDS[COMP_CWORD]}")) + COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur")) return } @@ -666,26 +671,40 @@ _git_config () local prv="${COMP_WORDS[COMP_CWORD-1]}" case "$prv" in branch.*.remote) - COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur")) + __gitcomp "$(__git_remotes)" return ;; branch.*.merge) - COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur")) + __gitcomp "$(__git_refs)" return ;; remote.*.fetch) local remote="${prv#remote.}" remote="${remote%.fetch}" - COMPREPLY=($(compgen -W "$(__git_refs_remotes "$remote")" \ - -- "$cur")) + __gitcomp "$(__git_refs_remotes "$remote")" return ;; remote.*.push) local remote="${prv#remote.}" remote="${remote%.push}" - COMPREPLY=($(compgen -W "$(git --git-dir="$(__gitdir)" \ + __gitcomp "$(git --git-dir="$(__gitdir)" \ 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 ;; *.*) @@ -695,41 +714,39 @@ _git_config () esac case "$cur" in --*) - COMPREPLY=($(compgen -W " + __gitcomp " --global --list --replace-all --get --get-all --get-regexp --unset --unset-all - " -- "$cur")) + " return ;; branch.*.*) local pfx="${cur%.*}." cur="${cur##*.}" - COMPREPLY=($(compgen -P "$pfx" -W "remote merge" -- "$cur")) + __gitcomp "remote merge" "$pfx" "$cur" return ;; branch.*) local pfx="${cur%.*}." cur="${cur#*.}" - COMPREPLY=($(compgen -P "$pfx" -S . \ - -W "$(__git_heads)" -- "$cur")) + __gitcomp "$(__git_heads)" "$pfx" "$cur" "." return ;; remote.*.*) local pfx="${cur%.*}." cur="${cur##*.}" - COMPREPLY=($(compgen -P "$pfx" -W "url fetch push" -- "$cur")) + __gitcomp "url fetch push" "$pfx" "$cur" return ;; remote.*) local pfx="${cur%.*}." cur="${cur#*.}" - COMPREPLY=($(compgen -P "$pfx" -S . \ - -W "$(__git_remotes)" -- "$cur")) + __gitcomp "$(__git_remotes)" "$pfx" "$cur" "." return ;; esac - COMPREPLY=($(compgen -W " + __gitcomp " apply.whitespace core.fileMode core.gitProxy @@ -741,40 +758,67 @@ _git_config () core.warnAmbiguousRefs core.compression core.legacyHeaders - i18n.commitEncoding - i18n.logOutputEncoding - diff.color + core.packedGitWindowSize + core.packedGitLimit + color.branch + color.branch.current + color.branch.local + color.branch.remote + color.branch.plain 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.renames - pager.color - color.pager - status.color - color.status - log.showroot - show.difftree - showbranch.default - whatchanged.difftree + fetch.unpackLimit + format.headers + gitcvs.enabled + gitcvs.logfile + gc.reflogexpire + gc.reflogexpireunreachable + gc.rerereresolved + gc.rerereunresolved http.sslVerify http.sslCert http.sslKey http.sslCAInfo http.sslCAPath http.maxRequests - http.lowSpeedLimit http.lowSpeedTime + http.lowSpeedLimit + http.lowSpeedTime http.noEPSV - pack.window - repack.useDeltaBaseOffset - pull.octopus pull.twohead + i18n.commitEncoding + i18n.logOutputEncoding + log.showroot merge.summary + merge.verbosity + pack.window + pull.octopus + pull.twohead + repack.useDeltaBaseOffset + show.difftree + showbranch.default + tar.umask + transfer.unpackLimit receive.unpackLimit receive.denyNonFastForwards - user.name user.email - tar.umask - gitcvs.enabled - gitcvs.logfile + user.name + user.email + user.signingkey + whatchanged.difftree branch. remote. - " -- "$cur")) + " } _git_reset () From b3391775e87bed073b93a0a534169a794eceebd7 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 4 Feb 2007 02:38:43 -0500 Subject: [PATCH 7/8] bash: Support unique completion when possible. Because our use of -o nospace prevents bash from adding a trailing space when a completion is unique and has been fully completed, we need to perform this addition on our own. This (large) change converts all existing uses of compgen to our wrapper __gitcomp which attempts to handle this by tacking a trailing space onto the end of each offered option. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 190 ++++++++++++------------- 1 file changed, 91 insertions(+), 99 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 38d61210a2..3b1f100f1b 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -65,7 +65,7 @@ __gitcomp () { local all c s=$'\n' IFS=' '$'\t'$'\n' local cur="${COMP_WORDS[COMP_CWORD]}" - if [ -n "$2" ]; then + if [ $# -gt 2 ]; then cur="$3" fi for c in $1; do @@ -219,7 +219,7 @@ __git_complete_file () -- "$cur")) ;; *) - COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur")) + __gitcomp "$(__git_refs)" ;; esac } @@ -231,15 +231,18 @@ __git_complete_revlist () *...*) pfx="${cur%...*}..." cur="${cur#*...}" - COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur")) + __gitcomp "$(__git_refs)" "$pfx" "$cur" ;; *..*) pfx="${cur%..*}.." cur="${cur#*..}" - COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur")) + __gitcomp "$(__git_refs)" "$pfx" "$cur" + ;; + *.) + __gitcomp "$cur." ;; *) - COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur")) + __gitcomp "$(__git_refs)" ;; esac } @@ -353,22 +356,19 @@ _git_am () { local cur="${COMP_WORDS[COMP_CWORD]}" if [ -d .dotest ]; then - COMPREPLY=($(compgen -W " - --skip --resolved - " -- "$cur")) + __gitcomp "--skip --resolved" return fi case "$cur" in --whitespace=*) - COMPREPLY=($(compgen -W "$__git_whitespacelist" \ - -- "${cur##--whitespace=}")) + __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}" return ;; --*) - COMPREPLY=($(compgen -W " + __gitcomp " --signoff --utf8 --binary --3way --interactive --whitespace= - " -- "$cur")) + " return esac COMPREPLY=() @@ -379,17 +379,16 @@ _git_apply () local cur="${COMP_WORDS[COMP_CWORD]}" case "$cur" in --whitespace=*) - COMPREPLY=($(compgen -W "$__git_whitespacelist" \ - -- "${cur##--whitespace=}")) + __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}" return ;; --*) - COMPREPLY=($(compgen -W " + __gitcomp " --stat --numstat --summary --check --index --cached --index-info --reverse --reject --unidiff-zero --apply --no-add --exclude= --whitespace= --inaccurate-eof --verbose - " -- "$cur")) + " return esac COMPREPLY=() @@ -400,9 +399,7 @@ _git_add () local cur="${COMP_WORDS[COMP_CWORD]}" case "$cur" in --*) - COMPREPLY=($(compgen -W " - --interactive - " -- "$cur")) + __gitcomp "--interactive" return esac COMPREPLY=() @@ -410,14 +407,12 @@ _git_add () _git_branch () { - local cur="${COMP_WORDS[COMP_CWORD]}" - COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur")) + __gitcomp "$(__git_refs)" } _git_checkout () { - local cur="${COMP_WORDS[COMP_CWORD]}" - COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur")) + __gitcomp "$(__git_refs)" } _git_cherry_pick () @@ -425,12 +420,10 @@ _git_cherry_pick () local cur="${COMP_WORDS[COMP_CWORD]}" case "$cur" in --*) - COMPREPLY=($(compgen -W " - --edit --no-commit - " -- "$cur")) + __gitcomp "--edit --no-commit" ;; *) - COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur")) + __gitcomp "$(__git_refs)" ;; esac } @@ -440,10 +433,10 @@ _git_commit () local cur="${COMP_WORDS[COMP_CWORD]}" case "$cur" in --*) - COMPREPLY=($(compgen -W " + __gitcomp " --all --author= --signoff --verify --no-verify --edit --amend --include --only - " -- "$cur")) + " return esac COMPREPLY=() @@ -456,8 +449,7 @@ _git_diff () _git_diff_tree () { - local cur="${COMP_WORDS[COMP_CWORD]}" - COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur")) + __gitcomp "$(__git_refs)" } _git_fetch () @@ -466,16 +458,15 @@ _git_fetch () case "${COMP_WORDS[0]},$COMP_CWORD" in git-fetch*,1) - COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur")) + __gitcomp "$(__git_remotes)" ;; git,2) - COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur")) + __gitcomp "$(__git_remotes)" ;; *) case "$cur" in *:*) - cur="${cur#*:}" - COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur")) + __gitcomp "$(__git_refs)" "" "${cur#*:}" ;; *) local remote @@ -483,7 +474,7 @@ _git_fetch () git-fetch) remote="${COMP_WORDS[1]}" ;; git) remote="${COMP_WORDS[2]}" ;; esac - COMPREPLY=($(compgen -W "$(__git_refs2 "$remote")" -- "$cur")) + __gitcomp "$(__git_refs2 "$remote")" ;; esac ;; @@ -495,7 +486,7 @@ _git_format_patch () local cur="${COMP_WORDS[COMP_CWORD]}" case "$cur" in --*) - COMPREPLY=($(compgen -W " + __gitcomp " --stdout --attach --thread --output-directory --numbered --start-number @@ -503,7 +494,7 @@ _git_format_patch () --signoff --in-reply-to= --full-index --binary - " -- "$cur")) + " return ;; esac @@ -512,8 +503,7 @@ _git_format_patch () _git_ls_remote () { - local cur="${COMP_WORDS[COMP_CWORD]}" - COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur")) + __gitcomp "$(__git_remotes)" } _git_ls_tree () @@ -526,13 +516,13 @@ _git_log () local cur="${COMP_WORDS[COMP_CWORD]}" case "$cur" in --pretty=*) - COMPREPLY=($(compgen -W " + __gitcomp " oneline short medium full fuller email raw - " -- "${cur##--pretty=}")) + " "" "${cur##--pretty=}" return ;; --*) - COMPREPLY=($(compgen -W " + __gitcomp " --max-count= --max-age= --since= --after= --min-age= --before= --until= --root --not --topo-order --date-order @@ -542,7 +532,7 @@ _git_log () --author= --committer= --grep= --all-match --pretty= --name-status --name-only - " -- "$cur")) + " return ;; esac @@ -554,34 +544,31 @@ _git_merge () local cur="${COMP_WORDS[COMP_CWORD]}" case "${COMP_WORDS[COMP_CWORD-1]}" in -s|--strategy) - COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur")) + __gitcomp "$(__git_merge_strategies)" return esac case "$cur" in --strategy=*) - COMPREPLY=($(compgen -W "$(__git_merge_strategies)" \ - -- "${cur##--strategy=}")) + __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}" return ;; --*) - COMPREPLY=($(compgen -W " + __gitcomp " --no-commit --no-summary --squash --strategy - " -- "$cur")) + " return esac - COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur")) + __gitcomp "$(__git_refs)" } _git_merge_base () { - local cur="${COMP_WORDS[COMP_CWORD]}" - COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur")) + __gitcomp "$(__git_refs)" } _git_name_rev () { - local cur="${COMP_WORDS[COMP_CWORD]}" - COMPREPLY=($(compgen -W "--tags --all --stdin" -- "$cur")) + __gitcomp "--tags --all --stdin" } _git_pull () @@ -590,10 +577,10 @@ _git_pull () case "${COMP_WORDS[0]},$COMP_CWORD" in git-pull*,1) - COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur")) + __gitcomp "$(__git_remotes)" ;; git,2) - COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur")) + __gitcomp "$(__git_remotes)" ;; *) local remote @@ -601,7 +588,7 @@ _git_pull () git-pull) remote="${COMP_WORDS[1]}" ;; git) remote="${COMP_WORDS[2]}" ;; esac - COMPREPLY=($(compgen -W "$(__git_refs "$remote")" -- "$cur")) + __gitcomp "$(__git_refs "$remote")" ;; esac } @@ -612,10 +599,10 @@ _git_push () case "${COMP_WORDS[0]},$COMP_CWORD" in git-push*,1) - COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur")) + __gitcomp "$(__git_remotes)" ;; git,2) - COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur")) + __gitcomp "$(__git_remotes)" ;; *) case "$cur" in @@ -625,11 +612,10 @@ _git_push () git-push) remote="${COMP_WORDS[1]}" ;; git) remote="${COMP_WORDS[2]}" ;; esac - cur="${cur#*:}" - COMPREPLY=($(compgen -W "$(__git_refs "$remote")" -- "$cur")) + __gitcomp "$(__git_refs "$remote")" "" "${cur#*:}" ;; *) - COMPREPLY=($(compgen -W "$(__git_refs2)" -- "$cur")) + __gitcomp "$(__git_refs2)" ;; esac ;; @@ -640,29 +626,24 @@ _git_rebase () { local cur="${COMP_WORDS[COMP_CWORD]}" if [ -d .dotest ]; then - COMPREPLY=($(compgen -W " - --continue --skip --abort - " -- "$cur")) + __gitcomp "--continue --skip --abort" return fi case "${COMP_WORDS[COMP_CWORD-1]}" in -s|--strategy) - COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur")) + __gitcomp "$(__git_merge_strategies)" return esac case "$cur" in --strategy=*) - COMPREPLY=($(compgen -W "$(__git_merge_strategies)" \ - -- "${cur##--strategy=}")) + __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}" return ;; --*) - COMPREPLY=($(compgen -W " - --onto --merge --strategy - " -- "$cur")) + __gitcomp "--onto --merge --strategy" return esac - COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur")) + __gitcomp "$(__git_refs)" } _git_config () @@ -824,8 +805,13 @@ _git_config () _git_reset () { local cur="${COMP_WORDS[COMP_CWORD]}" - local opt="--mixed --hard --soft" - COMPREPLY=($(compgen -W "$opt $(__git_refs)" -- "$cur")) + case "$cur" in + --*) + __gitcomp "--mixed --hard --soft" + return + ;; + esac + __gitcomp "$(__git_refs)" } _git_show () @@ -833,13 +819,13 @@ _git_show () local cur="${COMP_WORDS[COMP_CWORD]}" case "$cur" in --pretty=*) - COMPREPLY=($(compgen -W " + __gitcomp " oneline short medium full fuller email raw - " -- "${cur##--pretty=}")) + " "" "${cur##--pretty=}" return ;; --*) - COMPREPLY=($(compgen -W "--pretty=" -- "$cur")) + __gitcomp "--pretty=" return ;; esac @@ -906,32 +892,38 @@ _git () _gitk () { local cur="${COMP_WORDS[COMP_CWORD]}" - COMPREPLY=($(compgen -W "--all $(__git_refs)" -- "$cur")) + case "$cur" in + --*) + __gitcomp "--not --all" + return + ;; + esac + __gitcomp "$(__git_refs)" } complete -o default -o nospace -F _git git -complete -o default -F _gitk gitk -complete -o default -F _git_am git-am -complete -o default -F _git_apply git-apply -complete -o default -F _git_branch git-branch -complete -o default -F _git_checkout git-checkout -complete -o default -F _git_cherry_pick git-cherry-pick -complete -o default -F _git_commit git-commit +complete -o default -o nospace -F _gitk gitk +complete -o default -o nospace -F _git_am git-am +complete -o default -o nospace -F _git_apply git-apply +complete -o default -o nospace -F _git_branch git-branch +complete -o default -o nospace -F _git_checkout git-checkout +complete -o default -o nospace -F _git_cherry_pick git-cherry-pick +complete -o default -o nospace -F _git_commit git-commit complete -o default -o nospace -F _git_diff git-diff -complete -o default -F _git_diff_tree git-diff-tree +complete -o default -o nospace -F _git_diff_tree git-diff-tree complete -o default -o nospace -F _git_fetch git-fetch complete -o default -o nospace -F _git_format_patch git-format-patch complete -o default -o nospace -F _git_log git-log -complete -o default -F _git_ls_remote git-ls-remote +complete -o default -o nospace -F _git_ls_remote git-ls-remote complete -o default -o nospace -F _git_ls_tree git-ls-tree -complete -o default -F _git_merge git-merge -complete -o default -F _git_merge_base git-merge-base -complete -o default -F _git_name_rev git-name-rev +complete -o default -o nospace -F _git_merge git-merge +complete -o default -o nospace -F _git_merge_base git-merge-base +complete -o default -o nospace -F _git_name_rev git-name-rev complete -o default -o nospace -F _git_pull git-pull complete -o default -o nospace -F _git_push git-push -complete -o default -F _git_rebase git-rebase -complete -o default -F _git_config git-config -complete -o default -F _git_reset git-reset +complete -o default -o nospace -F _git_rebase git-rebase +complete -o default -o nospace -F _git_config git-config +complete -o default -o nospace -F _git_reset git-reset complete -o default -o nospace -F _git_show git-show complete -o default -o nospace -F _git_log git-show-branch complete -o default -o nospace -F _git_log git-whatchanged @@ -941,19 +933,19 @@ complete -o default -o nospace -F _git_log git-whatchanged # included the '.exe' suffix. # if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then -complete -o default -F _git_add git-add.exe -complete -o default -F _git_apply git-apply.exe +complete -o default -o nospace -F _git_add git-add.exe +complete -o default -o nospace -F _git_apply git-apply.exe complete -o default -o nospace -F _git git.exe -complete -o default -F _git_branch git-branch.exe +complete -o default -o nospace -F _git_branch git-branch.exe complete -o default -o nospace -F _git_diff git-diff.exe complete -o default -o nospace -F _git_diff_tree git-diff-tree.exe complete -o default -o nospace -F _git_format_patch git-format-patch.exe complete -o default -o nospace -F _git_log git-log.exe complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe -complete -o default -F _git_merge_base git-merge-base.exe -complete -o default -F _git_name_rev git-name-rev.exe +complete -o default -o nospace -F _git_merge_base git-merge-base.exe +complete -o default -o nospace -F _git_name_rev git-name-rev.exe complete -o default -o nospace -F _git_push git-push.exe -complete -o default -F _git_config git-config +complete -o default -o nospace -F _git_config git-config complete -o default -o nospace -F _git_show git-show.exe complete -o default -o nospace -F _git_log git-show-branch.exe complete -o default -o nospace -F _git_log git-whatchanged.exe From ec8048913217d8ff6e54950a0cb8ab2e739a1d1f Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 4 Feb 2007 02:38:47 -0500 Subject: [PATCH 8/8] bash: Support internal revlist options better. format-patch/log/whatchanged all take --not and --all as options to the internal revlist process. So these should be supported as possible completions. gitk takes anything rev-list/log/whatchanged takes, so we should use complete_revlist to handle its options. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 3b1f100f1b..466cc32f4c 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -494,6 +494,7 @@ _git_format_patch () --signoff --in-reply-to= --full-index --binary + --not --all " return ;; @@ -532,6 +533,7 @@ _git_log () --author= --committer= --grep= --all-match --pretty= --name-status --name-only + --not --all " return ;; @@ -898,7 +900,7 @@ _gitk () return ;; esac - __gitcomp "$(__git_refs)" + __git_complete_revlist } complete -o default -o nospace -F _git git