Skip to content
  • Chayoung You's avatar
    zsh: complete unquoted paths with spaces correctly · 7a478b36
    Chayoung You authored and Junio C Hamano's avatar Junio C Hamano committed
    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: default avatarChayoung You <yousbe@gmail.com>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    7a478b36