diff mbox series

completion: escape metacharacters when completing paths

Message ID 20181226160835.66342-1-yousbe@gmail.com (mailing list archive)
State New, archived
Headers show
Series completion: escape metacharacters when completing paths | expand

Commit Message

Chayoung You Dec. 26, 2018, 4:08 p.m. UTC
The following is the description of -Q flag of zsh compadd [1]:

  This flag instructs the completion code not to quote any
  metacharacters in the words when inserting them into the command line.

Let's say there is a file named 'foo bar.txt' in repository, but it's
not yet added to the repository. Then the following command triggers a
completion:

  git add fo<Tab>
  git add 'fo<Tab>
  git add "fo<Tab>

The completion results in bash:

  git add foo\ bar.txt
  git add 'foo bar.txt'
  git add "foo bar.txt"

While them in zsh:

  git add foo bar.txt
  git add 'foo bar.txt'
  git add "foo bar.txt"

The main cause of this behavior is __gitcomp_file_direct(). The both
implementions of bash and zsh are called with an argument 'foo bar.txt',
but only bash adds a backslash before a space on command line.

[1]: http://zsh.sourceforge.net/Doc/Release/Completion-Widgets.html

Signed-off-by: Chayoung You <yousbe@gmail.com>
---
 contrib/completion/git-completion.bash | 4 ++--
 contrib/completion/git-completion.zsh  | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

Comments

Junio C Hamano Dec. 28, 2018, 11:25 p.m. UTC | #1
Chayoung You <yousbe@gmail.com> writes:

> Subject: Re: [PATCH] completion: escape metacharacters when completing paths

I am not a zsh user, but from the patch text I am getting the
impression that this patch is only about zsh.  If so, please help
readers of "git shortlog" by saying so in the title.

	Subject: zsh: complete unquoted paths with spaces correctly

or something like that, perhaps?

> Let's say there is a file named 'foo bar.txt' in repository, but it's
> not yet added to the repository. Then the following command triggers a
> completion:
>
>   git add fo<Tab>
>   git add 'fo<Tab>
>   git add "fo<Tab>
>
> The completion results in bash:
>
>   git add foo\ bar.txt
>   git add 'foo bar.txt'
>   git add "foo bar.txt"
>
> While them in zsh:
>
>   git add foo bar.txt
>   git add 'foo bar.txt'
>   git add "foo bar.txt"

You leave it unsaid what you think is wrong, and what you think
should be the right output, before saying "cause of this is...".

I do not think it is given that "git add fo<TAB>" should be
completed to "git add foo\ bar.txt".  It would also be OK if the
completion produced "git add 'foo bar.txt'", for example.  So what
your ideal output is is rather important, and by doing that you end
up with saying what problem you have with the current output is.

So, say something here, perhaps like...

	The first one, where the pathname is not enclosed in quotes,
	should escape the SP with a backslash, just like bash
	completion does.
diff mbox series

Patch

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 9e8ec95c3..816ee3280 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2993,7 +2993,7 @@  if [[ -n ${ZSH_VERSION-} ]] &&
 
 		local IFS=$'\n'
 		compset -P '*[=:]'
-		compadd -Q -f -- ${=1} && _ret=0
+		compadd -f -- ${=1} && _ret=0
 	}
 
 	__gitcomp_file ()
@@ -3002,7 +3002,7 @@  if [[ -n ${ZSH_VERSION-} ]] &&
 
 		local IFS=$'\n'
 		compset -P '*[=:]'
-		compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
+		compadd -p "${2-}" -f -- ${=1} && _ret=0
 	}
 
 	_git ()
diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 049d6b80f..886bf95d1 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -99,7 +99,7 @@  __gitcomp_file_direct ()
 
 	local IFS=$'\n'
 	compset -P '*[=:]'
-	compadd -Q -f -- ${=1} && _ret=0
+	compadd -f -- ${=1} && _ret=0
 }
 
 __gitcomp_file ()
@@ -108,7 +108,7 @@  __gitcomp_file ()
 
 	local IFS=$'\n'
 	compset -P '*[=:]'
-	compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
+	compadd -p "${2-}" -f -- ${=1} && _ret=0
 }
 
 __git_zsh_bash_func ()