m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-16 07:13:48 -05:00

Fix powershell escaping

This commit is contained in:
Rashil Gandhi
2021-10-27 13:20:40 +05:30
committed by Junegunn Choi
parent edac9820b5
commit 7c3f42bbba
2 changed files with 10 additions and 10 deletions

View File

@@ -37,7 +37,7 @@ func quoteEntry(entry string) string {
return "^" + match return "^" + match
}) })
} else if strings.Contains(shell, "pwsh") || strings.Contains(shell, "powershell") { } else if strings.Contains(shell, "pwsh") || strings.Contains(shell, "powershell") {
escaped := strings.Replace(entry, `"`, `""`, -1) escaped := strings.Replace(entry, `"`, `\"`, -1)
return "'" + strings.Replace(escaped, "'", "''", -1) + "'" return "'" + strings.Replace(escaped, "'", "''", -1) + "'"
} else { } else {
return "'" + strings.Replace(entry, "'", "'\\''", -1) + "'" return "'" + strings.Replace(entry, "'", "'\\''", -1) + "'"

View File

@@ -39,24 +39,24 @@ func ExecCommand(command string, setpgid bool) *exec.Cmd {
// NOTE: For "powershell", we should ideally set output encoding to UTF8, // NOTE: For "powershell", we should ideally set output encoding to UTF8,
// but it is left as is now because no adverse effect has been observed. // but it is left as is now because no adverse effect has been observed.
func ExecCommandWith(shell string, command string, setpgid bool) *exec.Cmd { func ExecCommandWith(shell string, command string, setpgid bool) *exec.Cmd {
var commandline string var cmd *exec.Cmd
if strings.Contains(shell, "cmd") { if strings.Contains(shell, "cmd") {
commandline = fmt.Sprintf(` /v:on/s/c "%s"`, command) cmd = exec.Command(shell)
} else if strings.Contains(shell, "pwsh") || strings.Contains(shell, "powershell") {
commandline = fmt.Sprintf(` -NoProfile -Command "& { %s }"`, command)
}
if len(commandline) == 0 {
cmd := exec.Command(shell, "-c", command)
cmd.SysProcAttr = &syscall.SysProcAttr{ cmd.SysProcAttr = &syscall.SysProcAttr{
HideWindow: false, HideWindow: false,
CmdLine: fmt.Sprintf(` /v:on/s/c "%s"`, command),
CreationFlags: 0, CreationFlags: 0,
} }
return cmd return cmd
} }
cmd := exec.Command(shell)
if strings.Contains(shell, "pwsh") || strings.Contains(shell, "powershell") {
cmd = exec.Command(shell, "-NoProfile", "-Command", command)
} else {
cmd = exec.Command(shell, "-c", command)
}
cmd.SysProcAttr = &syscall.SysProcAttr{ cmd.SysProcAttr = &syscall.SysProcAttr{
HideWindow: false, HideWindow: false,
CmdLine: commandline,
CreationFlags: 0, CreationFlags: 0,
} }
return cmd return cmd