Fix shell escaping for fish

Fix #3224
This commit is contained in:
Junegunn Choi 2023-12-25 17:35:44 +09:00
parent 0e999482cb
commit 41d4d70b98
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
1 changed files with 15 additions and 1 deletions

View File

@ -11,6 +11,20 @@ import (
"golang.org/x/sys/unix"
)
var escaper *strings.Replacer
func init() {
tokens := strings.Split(os.Getenv("SHELL"), "/")
if tokens[len(tokens)-1] == "fish" {
// https://fishshell.com/docs/current/language.html#quotes
// > The only meaningful escape sequences in single quotes are \', which
// > escapes a single quote and \\, which escapes the backslash symbol.
escaper = strings.NewReplacer("\\", "\\\\", "'", "\\'")
} else {
escaper = strings.NewReplacer("'", "'\\''")
}
}
func notifyOnResize(resizeChan chan<- os.Signal) {
signal.Notify(resizeChan, syscall.SIGWINCH)
}
@ -29,5 +43,5 @@ func notifyOnCont(resizeChan chan<- os.Signal) {
}
func quoteEntry(entry string) string {
return "'" + strings.Replace(entry, "'", "'\\''", -1) + "'"
return "'" + escaper.Replace(entry) + "'"
}