diff options
author | Rashil Gandhi <46838874+rashil2000@users.noreply.github.com> | 2021-10-22 21:39:47 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-23 01:09:47 +0900 |
commit | 84a47f71029992fe804e506a6128643bffbb598c (patch) | |
tree | 7aef3711567f5303b1077ec6ca9e656436f36a2e /src/terminal_windows.go | |
parent | 97ae8afb6f83b545eac530a689d7b3d46e20eec1 (diff) |
Respect SHELL env var on Windows (#2641)
This makes fzf respect SHELL environment variable on Windows, like it does on *nix, whenever defined.
Close #2638
Diffstat (limited to 'src/terminal_windows.go')
-rw-r--r-- | src/terminal_windows.go | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/terminal_windows.go b/src/terminal_windows.go index d4262b65..7ba64dff 100644 --- a/src/terminal_windows.go +++ b/src/terminal_windows.go @@ -21,10 +21,25 @@ func notifyOnCont(resizeChan chan<- os.Signal) { } func quoteEntry(entry string) string { - escaped := strings.Replace(entry, `\`, `\\`, -1) - escaped = `"` + strings.Replace(escaped, `"`, `\"`, -1) + `"` - r, _ := regexp.Compile(`[&|<>()@^%!"]`) - return r.ReplaceAllStringFunc(escaped, func(match string) string { - return "^" + match - }) + 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") { + escaped := strings.Replace(entry, `"`, `""`, -1) + return "'" + strings.Replace(escaped, "'", "''", -1) + "'" + } else { + return "'" + strings.Replace(entry, "'", "'\\''", -1) + "'" + } } |