Grepper isn't properly quoting search queries on Windows
- Dominant language
- Vim Script
- Stars
- 1.2k
- Forks
- 62
- PR merge metrics
- No merged PRs in 30d
Description
In my .vimrc, the only configuration related to Grepper is the following two mappings:
```
nmap gs (GrepperOperator)
xmap gs (GrepperOperator)
```
Grepper chooses ag by default, and I'll use ag in my examples below, though I've also tried swapping ag for rg with the same results.
I created a very simple test case of a single folder named "test" whose contents are the single file named "test.txt" whose contents are the single line "test1 test2". In all further discussion, this is my present working directory and only buffer.
In Windows, if I position the cursor on column 1 and type "gs2w" (grep search two words), or if I visually select "test1 test2" and then type "gs" (grep search visual selection), then the following error is generated:
```
|| ERR: Error opening directory test2: No such file or directory
```
Strangely, the command displayed in the status line does appear to be properly (double) quoted:
```
[Quickfix List] ag --vimgrep -- "test1 test2"
```
That same command returns the expected result when typed directly at the Windows shell.
However, the error in Vim certainly indicates that ag as called by Grepper is treating the second word after the space as a path argument rather than part of the search pattern.
When I do the exact same experiments in macOS, the Grepper search is successful and no error is generated:
```
test.txt|1 col 1| test1 test2
```
Here the command displayed in the status bar is similar to Windows, though the quotes are single rather than double, which makes sense since I'm using Bash on macOS:
```
[Quickfix List] ag --vimgrep -- 'test1 test2'
```
I also did some experimentation using the Grepper prompt instead of the operator.
In macOS, I can search at the Grepper prompt for 'test1 test2' or "test1 test2" (single or double quotes) and I'll get the same successful result. This makes sense because there aren't any special characters which need to be escaped and Bash can handle both types of quotes.
However, in Windows, only the Grepper prompt search for 'test1 test2' returns a successful result, whereas "test1 test2" returns the same error as when trying to use the operator.
To me, this is particularly odd behavior since the Windows shell is only supposed to work with the double quotes rather than the single. Using single quotes directly at the Windows shell generates the same error as using double quotes at the Grepper prompt.
Hence, Grepper appears to be sending to the Windows shell the opposite quotes of what is being displayed on the Vim status line.
Here's my environment:
Windows 10 Enterprise 16299.192
vim 8.0.1473 (via Chocolatey)
ag 2.1.0 (via Chocolatey)
rg 0.7.1 (via Chocolatey)
vim-grepper 1.4 (via vim-plug)
macoS 10.13.2
vim 8.0.1450 (via Homebrew)
ag 2.1.0 (via Homebrew)
rg 0.7.1 (via Homebrew)
vim-grepper 1.4 (via vim-plug)
Let me know if there is anything else I can provide that would help debug. Cheers.
Contributor guide
Research direction
Start by tracing how the operator and prompt build and execute ag or rg commands on Windows, comparing the displayed command with the arguments actually passed to the shell. Reproduce a multiword search such as "test1 test2" and consider the issue done when quoted searches work through both interfaces on Windows without regressing macOS behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- vim
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100