mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-08-04 14:46:03 +00:00
Utility code to find longest common prefix/suffix and to quote strings for various shells
This commit is contained in:
parent
1ff4f2df4f
commit
cbbda23e01
3 changed files with 126 additions and 0 deletions
26
tools/utils/shell.go
Normal file
26
tools/utils/shell.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// License: GPLv3 Copyright: 2022, Kovid Goyal, <kovid at kovidgoyal.net>
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
// Quotes arbitrary strings for bash, dash and zsh
|
||||
func QuoteStringForSH(x string) string {
|
||||
parts := strings.Split(x, "'")
|
||||
for i, p := range parts {
|
||||
parts[i] = "'" + p + "'"
|
||||
}
|
||||
return strings.Join(parts, "\"'\"")
|
||||
}
|
||||
|
||||
// Quotes arbitrary strings for fish
|
||||
func QuoteStringForFish(x string) string {
|
||||
x = strings.ReplaceAll(x, "\\", "\\\\")
|
||||
x = strings.ReplaceAll(x, "'", "\\'")
|
||||
return "'" + x + "'"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue