diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2023-12-25 17:35:44 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2023-12-25 17:35:44 +0900 |
commit | 41d4d70b985f665c8ecc66b83aa10209c8dfbbfd (patch) | |
tree | 4852445b4e3576331c354d760ea9af880a6e016b | |
parent | 0e999482cb13c194427d47687a49473e1e240a20 (diff) |
Fix shell escaping for fish
Fix #3224
-rw-r--r-- | src/terminal_unix.go | 16 |
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) + "'" } |