zsh completion; Fix leading ~ in filenames being quoted on insertion into commandline

This commit is contained in:
Kovid Goyal
2023-01-04 11:07:56 +05:30
parent 035c3de4bb
commit c83a8b0773
2 changed files with 26 additions and 2 deletions

View File

@@ -24,3 +24,18 @@ func QuoteStringForFish(x string) string {
x = strings.ReplaceAll(x, "'", "\\'")
return "'" + x + "'"
}
// Escapes common shell meta characters
func EscapeSHMetaCharacters(x string) string {
const metachars = "\\|&;<>()$'\" \n\t"
ans := strings.Builder{}
ans.Grow(len(x) + 32)
for _, ch := range x {
switch ch {
case '\\', '|', '&', ';', '<', '>', '(', ')', '$', '\'', '"', ' ', '\n', '\t':
ans.WriteRune('\\')
}
ans.WriteRune(ch)
}
return ans.String()
}