Skip to content

Commit 7a478b3

Browse files
yousgitster
authored andcommitted
zsh: complete unquoted paths with spaces correctly
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 first one, where the pathname is not enclosed in quotes, should escape the space with a backslash, just like bash completion does. Otherwise, this leads git to think there are two files; foo, and 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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b21ebb6 commit 7a478b3

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

contrib/completion/git-completion.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,7 +2993,7 @@ if [[ -n ${ZSH_VERSION-} ]] &&
29932993

29942994
local IFS=$'\n'
29952995
compset -P '*[=:]'
2996-
compadd -Q -f -- ${=1} && _ret=0
2996+
compadd -f -- ${=1} && _ret=0
29972997
}
29982998

29992999
__gitcomp_file ()
@@ -3002,7 +3002,7 @@ if [[ -n ${ZSH_VERSION-} ]] &&
30023002

30033003
local IFS=$'\n'
30043004
compset -P '*[=:]'
3005-
compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
3005+
compadd -p "${2-}" -f -- ${=1} && _ret=0
30063006
}
30073007

30083008
_git ()

contrib/completion/git-completion.zsh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ __gitcomp_file_direct ()
9999

100100
local IFS=$'\n'
101101
compset -P '*[=:]'
102-
compadd -Q -f -- ${=1} && _ret=0
102+
compadd -f -- ${=1} && _ret=0
103103
}
104104

105105
__gitcomp_file ()
@@ -108,7 +108,7 @@ __gitcomp_file ()
108108

109109
local IFS=$'\n'
110110
compset -P '*[=:]'
111-
compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
111+
compadd -p "${2-}" -f -- ${=1} && _ret=0
112112
}
113113

114114
__git_zsh_bash_func ()

0 commit comments

Comments
 (0)