From 86ff357f2924287898f7cbefea6dac50c072335c Mon Sep 17 00:00:00 2001 From: rsteube Date: Thu, 25 Mar 2021 14:38:29 +0100 Subject: [PATCH 1/2] bash: re-enabled special characters --- internal/bash/action.go | 45 ++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/internal/bash/action.go b/internal/bash/action.go index 07f1e342d..e965f7f69 100644 --- a/internal/bash/action.go +++ b/internal/bash/action.go @@ -9,20 +9,33 @@ import ( ) var sanitizer = strings.NewReplacer( - `$`, ``, - "`", ``, "\n", ``, - `\`, ``, - `"`, ``, - `'`, ``, - `|`, ``, - `>`, ``, - `<`, ``, - `&`, ``, - `(`, ``, - `)`, ``, - `;`, ``, - `#`, ``, + "\r", ``, + "\t", ``, +) + +var quoter = strings.NewReplacer( + // seems readline provides quotation only for the filename completion (which would add suffixes) so do that here + `&`, `\&`, + `<`, `\<`, + `>`, `\>`, + "`", "\\`", + `'`, `\'`, + `"`, `\"`, + `{`, `\{`, + `}`, `\}`, + `$`, `\$`, + `#`, `\#`, + `|`, `\|`, + `?`, `\?`, + `(`, `\(`, + `)`, `\)`, + `;`, `\;`, + ` `, `\ `, + `[`, `\[`, + `]`, `\]`, + `*`, `\*`, + `\`, `\\`, ) func Sanitize(values ...string) []string { @@ -33,10 +46,6 @@ func Sanitize(values ...string) []string { return sanitized } -func EscapeSpace(s string) string { - return strings.Replace(s, " ", `\ `, -1) -} - func commonPrefix(a, b string) string { i := 0 for i < len(a) && i < len(b) && a[i] == b[i] { @@ -100,7 +109,7 @@ func ActionRawValues(callbackValue string, values ...common.RawValue) string { vals := make([]string, len(filtered)) for index, val := range filtered { if len(filtered) == 1 { - vals[index] = EscapeSpace(sanitizer.Replace(val.Value)) + vals[index] = quoter.Replace(sanitizer.Replace(val.Value)) } else { if val.Description != "" { vals[index] = fmt.Sprintf("%v (%v)", val.Display, sanitizer.Replace(val.Description)) From 31bad196f0566a1110561d51dfc1123734a47edb Mon Sep 17 00:00:00 2001 From: rsteube Date: Thu, 25 Mar 2021 14:49:46 +0100 Subject: [PATCH 2/2] dockerfile: removed bash-completion --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 96871e874..555fade95 100644 --- a/Dockerfile +++ b/Dockerfile @@ -100,7 +100,6 @@ RUN ln -s /carapace/example/example /usr/local/bin/example # bash RUN echo -e "\n\ PS1=$'\e[0;36mcarapace-bash \e[0m'\n\ -source /usr/share/bash-completion/bash_completion \n\ source <(example _carapace)" \ > ~/.bashrc