2016-10-24 00:44:56 +00:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package fzf
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
Add more tests of placeholder flags and simplify its logic (#2624)
* [tests] Test fzf's placeholders and escaping on practical commands
This tests some reasonable commands in fzf's templates (for commands,
previews, rebinds etc.), how are those commands escaped (backslashes,
double quotes), and documents if the output is executable in cmd.exe.
Both on Unix and Windows.
* [tests] Add testing of placeholder parsing and matching
Adds tests and bit of docs for the curly brackets placeholders in fzf's
template strings. Also tests the "placeholder" regex.
* [tests] Add more test cases of replacing placeholders focused on flags
Replacing placeholders in templates is already tested, this adds tests
that focus more on the parameters of placeholders - e.g. flags, token
ranges.
There is at least one test for each flag, not all combinations are
tested though.
* [refactoring] Split OS-specific function quoteEntry() to corresponding source file
This is minor refactoring, and also the function's test was made
crossplatform.
* [refactoring] Simplify replacePlaceholder function
Should be equivalent to the original, but has simpler structure.
2021-10-15 13:31:59 +00:00
|
|
|
"regexp"
|
|
|
|
"strings"
|
2016-10-24 00:44:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func notifyOnResize(resizeChan chan<- os.Signal) {
|
|
|
|
// TODO
|
|
|
|
}
|
2017-04-28 13:58:08 +00:00
|
|
|
|
|
|
|
func notifyStop(p *os.Process) {
|
|
|
|
// NOOP
|
|
|
|
}
|
|
|
|
|
|
|
|
func notifyOnCont(resizeChan chan<- os.Signal) {
|
|
|
|
// NOOP
|
|
|
|
}
|
Add more tests of placeholder flags and simplify its logic (#2624)
* [tests] Test fzf's placeholders and escaping on practical commands
This tests some reasonable commands in fzf's templates (for commands,
previews, rebinds etc.), how are those commands escaped (backslashes,
double quotes), and documents if the output is executable in cmd.exe.
Both on Unix and Windows.
* [tests] Add testing of placeholder parsing and matching
Adds tests and bit of docs for the curly brackets placeholders in fzf's
template strings. Also tests the "placeholder" regex.
* [tests] Add more test cases of replacing placeholders focused on flags
Replacing placeholders in templates is already tested, this adds tests
that focus more on the parameters of placeholders - e.g. flags, token
ranges.
There is at least one test for each flag, not all combinations are
tested though.
* [refactoring] Split OS-specific function quoteEntry() to corresponding source file
This is minor refactoring, and also the function's test was made
crossplatform.
* [refactoring] Simplify replacePlaceholder function
Should be equivalent to the original, but has simpler structure.
2021-10-15 13:31:59 +00:00
|
|
|
|
|
|
|
func quoteEntry(entry string) string {
|
2021-10-22 16:09:47 +00:00
|
|
|
shell := os.Getenv("SHELL")
|
|
|
|
if len(shell) == 0 {
|
|
|
|
shell = "cmd"
|
|
|
|
}
|
|
|
|
|
|
|
|
if strings.Contains(shell, "cmd") {
|
|
|
|
// backslash escaping is done here for applications
|
|
|
|
// (see ripgrep test case in terminal_test.go#TestWindowsCommands)
|
|
|
|
escaped := strings.Replace(entry, `\`, `\\`, -1)
|
|
|
|
escaped = `"` + strings.Replace(escaped, `"`, `\"`, -1) + `"`
|
|
|
|
// caret is the escape character for cmd shell
|
|
|
|
r, _ := regexp.Compile(`[&|<>()@^%!"]`)
|
|
|
|
return r.ReplaceAllStringFunc(escaped, func(match string) string {
|
|
|
|
return "^" + match
|
|
|
|
})
|
|
|
|
} else if strings.Contains(shell, "pwsh") || strings.Contains(shell, "powershell") {
|
2021-10-27 07:50:40 +00:00
|
|
|
escaped := strings.Replace(entry, `"`, `\"`, -1)
|
2021-10-22 16:09:47 +00:00
|
|
|
return "'" + strings.Replace(escaped, "'", "''", -1) + "'"
|
|
|
|
} else {
|
|
|
|
return "'" + strings.Replace(entry, "'", "'\\''", -1) + "'"
|
|
|
|
}
|
Add more tests of placeholder flags and simplify its logic (#2624)
* [tests] Test fzf's placeholders and escaping on practical commands
This tests some reasonable commands in fzf's templates (for commands,
previews, rebinds etc.), how are those commands escaped (backslashes,
double quotes), and documents if the output is executable in cmd.exe.
Both on Unix and Windows.
* [tests] Add testing of placeholder parsing and matching
Adds tests and bit of docs for the curly brackets placeholders in fzf's
template strings. Also tests the "placeholder" regex.
* [tests] Add more test cases of replacing placeholders focused on flags
Replacing placeholders in templates is already tested, this adds tests
that focus more on the parameters of placeholders - e.g. flags, token
ranges.
There is at least one test for each flag, not all combinations are
tested though.
* [refactoring] Split OS-specific function quoteEntry() to corresponding source file
This is minor refactoring, and also the function's test was made
crossplatform.
* [refactoring] Simplify replacePlaceholder function
Should be equivalent to the original, but has simpler structure.
2021-10-15 13:31:59 +00:00
|
|
|
}
|