git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] completion: dir-type optargs for am, format-patch
       [not found] <20240107214200.29684-1-britton.kerin@gmail.com>
@ 2024-01-07 21:42 ` Britton Leo Kerin
  2024-01-08 18:37   ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Britton Leo Kerin @ 2024-01-07 21:42 UTC (permalink / raw)
  To: git; +Cc: Britton Leo Kerin

Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
---
 contrib/completion/git-completion.bash | 38 ++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 185b47d802..c3b0a3699c 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1356,6 +1356,30 @@ __git_count_arguments ()
 	printf "%d" $c
 }
 
+
+# Complete actual dir (not pathspec), respecting any -C options.
+#
+# Usage: __git_complete_refs [<option>]...
+# --cur=<word>: The current dir to be completed.  Defaults to the current word.
+__git_complete_dir ()
+{
+	local cur_="$cur"
+
+	while test $# != 0; do
+		case "$1" in
+		--cur=*)	cur_="${1##--cur=}" ;;
+		*)		return 1 ;;
+		esac
+		shift
+	done
+
+	local context_dir=$(__git rev-parse --show-toplevel --show-prefix 2>/dev/null | paste -s -d '/' 2>/dev/null)
+	[ -d "$context_dir" ] || return
+
+	COMPREPLY=$(cd $context_dir 2>/dev/null && compgen -d -- "$cur_")
+}
+
+
 __git_whitespacelist="nowarn warn error error-all fix"
 __git_patchformat="mbox stgit stgit-series hg mboxrd"
 __git_showcurrentpatch="diff raw"
@@ -1374,6 +1398,10 @@ _git_am ()
 		__gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
 		return
 		;;
+	--directory=*)
+		__git_complete_dir --cur="${cur##--directory=}"
+		return
+		;;
 	--patch-format=*)
 		__gitcomp "$__git_patchformat" "" "${cur##--patch-format=}"
 		return
@@ -1867,7 +1895,17 @@ __git_format_patch_extra_options="
 
 _git_format_patch ()
 {
+	case "$prev,$cur" in
+	-o,*)
+		__git_complete_dir
+		return
+		;;
+	esac
 	case "$cur" in
+	--output-directory=*)
+		__git_complete_dir --cur="${cur##--output-directory=}"
+		return
+		;;
 	--thread=*)
 		__gitcomp "
 			deep shallow
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] completion: dir-type optargs for am, format-patch
  2024-01-07 21:42 ` [PATCH 1/1] completion: dir-type optargs for am, format-patch Britton Leo Kerin
@ 2024-01-08 18:37   ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2024-01-08 18:37 UTC (permalink / raw)
  To: Britton Leo Kerin; +Cc: git

"Britton Leo Kerin" <britton.kerin@gmail.com> writes:

> +	local context_dir=$(__git rev-parse --show-toplevel --show-prefix 2>/dev/null | paste -s -d '/' 2>/dev/null)

Is there a practical difference with the above with

	context_dir=$(pwd)

other than that it will give an empty string outside a git working tree?

If not, I suspect

	local inside

	inside=$(__git rev-parse --is-inside-work-tree) &&
	test "$inside" = true || return

	local context_dir=$(pwd)

might be clearer on the intent.

> +	[ -d "$context_dir" ] || return
> +
> +	COMPREPLY=$(cd $context_dir 2>/dev/null && compgen -d -- "$cur_")

Can $context_dir contain $IFS whitespaces here?

> +}

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-08 18:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20240107214200.29684-1-britton.kerin@gmail.com>
2024-01-07 21:42 ` [PATCH 1/1] completion: dir-type optargs for am, format-patch Britton Leo Kerin
2024-01-08 18:37   ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).