escape parentheses and other special characters in tab completion

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Florian WaltherandClaude Opus 5.5 committed 2026-10-06 11:16:17 +02:00
1 parent 82f9c90a39
commit eb8653c9f5
2 files changed
+42 -3

No files matched your search

+5 -3
View File
@@ -963,11 +963,13 @@ func currentWord(s string) (word string, start int, quote byte) {
return b.String(), start, quote
}
// escapeWord escapes characters that would otherwise be interpreted by shlex
// escapeWord escapes characters that would otherwise be interpreted by the
// shell. # and ~ are only special at the start of a word, so they are only
// escaped at the start of s.
func escapeWord(s string) string {
var b strings.Builder
for _, r := range s {
if strings.ContainsRune(" \t\\'\";|&<>*?[${", r) {
for i, r := range s {
if strings.ContainsRune(" \t\\'\"`;|&<>()*?[]{}$!", r) || (i == 0 && (r == '#' || r == '~')) {
b.WriteByte('\\')
}
b.WriteRune(r)