summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2023-12-25 17:35:44 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2023-12-25 17:35:44 +0900
commit41d4d70b985f665c8ecc66b83aa10209c8dfbbfd (patch)
tree4852445b4e3576331c354d760ea9af880a6e016b
parent0e999482cb13c194427d47687a49473e1e240a20 (diff)
Fix shell escaping for fish
Fix #3224
-rw-r--r--src/terminal_unix.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/terminal_unix.go b/src/terminal_unix.go
index 1ce7854e..c7fa7f12 100644
--- a/src/terminal_unix.go
+++ b/src/terminal_unix.go
@@ -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) + "'"
}