Skip to content
Myr

Fix shell escaping for fish

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix #3224

authored by Junegunn Choi · committed by Junegunn Choi · parent 0e99948 · Browse files · 1 file+15 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+15 added−1 removed

  • other:+15 added−1 removed

1 file+15 added−1 removed

modified:src/terminal_unix.go+15 added-1 removed
9 unmodified lines
1011 "golang.org/x/sys/unix"12)1314var escaper *strings.Replacer1516func init() {17 tokens := strings.Split(os.Getenv("SHELL"), "/")18 if tokens[len(tokens)-1] == "fish" {19 // https://fishshell.com/docs/current/language.html#quotes20 // > The only meaningful escape sequences in single quotes are \', which21 // > escapes a single quote and \\, which escapes the backslash symbol.22 escaper = strings.NewReplacer("\\", "\\\\", "'", "\\'")23 } else {24 escaper = strings.NewReplacer("'", "'\\''")25 }26}2728func notifyOnResize(resizeChan chan<- os.Signal) {29 signal.Notify(resizeChan, syscall.SIGWINCH)30}31
10 unmodified lines
42 signal.Notify(resizeChan, syscall.SIGCONT)43}4445func quoteEntry(entry string) string {32 return "'" + strings.Replace(entry, "'", "'\\''", -1) + "'"46 return "'" + escaper.Replace(entry) + "'"47}