git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/3] bash completion: teach fetch, pull, and push to complete their options

From
Jay Soffian <jaysoffian@gmail.com>
Date
Mar 6, 2009, 04:39 UTC
Message-ID
<5576c9f6e10a6efec0b2bbbd156a25852506cc49.1236314073.git.jaysoffian@gmail.com>
In-Reply-To
<cover.1236314073.git.jaysoffian@gmail.com>

fetch, pull, and push didn't know their options. They do now. merge's options are factored into a variable so they can be shared between _git_merge and _git_pull

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
 contrib/completion/git-completion.bash |   61 +++++++++++++++++++++++++++++---
 1 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 8924185..3ebedea 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -387,10 +387,11 @@ __git_complete_remote_or_refspec ()
 {
 	local cmd="${COMP_WORDS[1]}"
 	local cur="${COMP_WORDS[COMP_CWORD]}"
-	local i c=2 remote="" pfx="" lhs=1
+	local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
 	while [ $c -lt $COMP_CWORD ]; do
 		i="${COMP_WORDS[c]}"
 		case "$i" in
+		--all|--mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
 		-*) ;;
 		*) remote="$i"; break ;;
 		esac
@@ -400,6 +401,10 @@ __git_complete_remote_or_refspec ()
 		__gitcomp "$(__git_remotes)"
 		return
 	fi
+	if [ $no_complete_refspec = 1 ]; then
+		COMPREPLY=()
+		return
+	fi
 	[ "$remote" = "." ] && remote=
 	case "$cur" in
 	*:*)
@@ -899,8 +904,20 @@ _git_diff ()
 	__git_complete_file
 }
 
+__git_fetch_options="
+	--quiet --verbose --append --upload-pack --force --keep --depth=
+	--tags --no-tags
+"
+
 _git_fetch ()
 {
+	local cur="${COMP_WORDS[COMP_CWORD]}"
+	case "$cur" in
+	--*)
+		__gitcomp "$__git_fetch_options"
+		return
+		;;
+	esac
 	__git_complete_remote_or_refspec
 }
 
@@ -1100,6 +1117,11 @@ _git_log ()
 	__git_complete_revlist
 }
 
+__git_merge_options="
+	--no-commit --no-stat --log --no-log --squash --strategy
+	--commit --stat --no-squash --ff --no-ff
+"
+
 _git_merge ()
 {
 	__git_complete_strategy && return
@@ -1107,10 +1129,7 @@ _git_merge ()
 	local cur="${COMP_WORDS[COMP_CWORD]}"
 	case "$cur" in
 	--*)
-		__gitcomp "
-			--no-commit --no-stat --log --no-log --squash --strategy
-			--commit --stat --no-squash --ff --no-ff
-			"
+		__gitcomp "$__git_merge_options"
 		return
 	esac
 	__gitcomp "$(__git_refs)"
@@ -1159,11 +1178,43 @@ _git_name_rev ()
 
 _git_pull ()
 {
+	__git_complete_strategy && return
+
+	local cur="${COMP_WORDS[COMP_CWORD]}"
+	case "$cur" in
+	--*)
+		__gitcomp "
+			--rebase --no-rebase
+			$__git_merge_options
+			$__git_fetch_options
+		"
+		return
+		;;
+	esac
 	__git_complete_remote_or_refspec
 }
 
 _git_push ()
 {
+	local cur="${COMP_WORDS[COMP_CWORD]}"
+	case "${COMP_WORDS[COMP_CWORD-1]}" in
+	--repo)
+		__gitcomp "$(__git_remotes)"
+		return
+	esac
+	case "$cur" in
+	--repo=*)
+		__gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
+		return
+		;;
+	--*)
+		__gitcomp "
+			--all --mirror --tags --dry-run --force --verbose
+			--receive-pack= --repo=
+		"
+		return
+		;;
+	esac
 	__git_complete_remote_or_refspec
 }
 
-- 
1.6.2.rc2.332.g5d21b
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 12 of 14 in “improve bash completion of fetch, pull, and push”
  1. 0/3 improve bash completion of fetch, pull, and pushJay Soffian, Mar 6, 2009
  2. 1/3 bash completion: fix completion issues with fetch, pull, and pushJay Soffian, Mar 6, 2009
  3. Shawn O. PearceMar 6, 2009
  4. Nanako ShiraishiMar 11, 2009
  5. Jay SoffianMar 11, 2009
  6. 2/3 bash completion: refactor --strategy completionJay Soffian, Mar 6, 2009
  7. Shawn O. PearceMar 6, 2009
  8. Jay SoffianMar 6, 2009
  9. Shawn O. PearceMar 6, 2009
  10. Jay SoffianMar 6, 2009
  11. Shawn O. PearceMar 6, 2009
  12. 3/3 bash completion: teach fetch, pull, and push to complete their optionsJay Soffian, Mar 6, 2009
  13. Shawn O. PearceMar 6, 2009
  14. Sverre RabbelierMar 6, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.