Repository: rsteube/carapace (go)

Issue:
xonsh needs quotes for space
https://xon.sh/tutorial_subproc_strings.html#no-escape

```sh
gh issue list --label accessibility,tech\ debt,enhancement,colors
# unknown argument "debt,enhancement,colors"; please quote all values that have spaces
``

Pull request description:
xonsh: fix quotation
fixes #199


Patch:
diff --git a/internal/xonsh/action.go b/internal/xonsh/action.go
index 416ff95..d68047a 100644
--- a/internal/xonsh/action.go
+++ b/internal/xonsh/action.go
@@ -43,7 +43,7 @@ func ActionRawValues(callbackValue string, values ...common.RawValue) string {
 
 	vals := make([]string, len(filtered))
 	for index, val := range filtered {
-		vals[index] = fmt.Sprintf(`  RichCompletion('%v', display='%v', description='%v', prefix_len=0),`, strings.Replace(sanitizer.Replace(val.Value), " ", `\\ `, -1), sanitizer.Replace(val.Display), sanitizer.Replace(val.Description))
+		vals[index] = fmt.Sprintf(`  RichCompletion('%v', display='%v', description='%v', prefix_len=0),`, sanitizer.Replace(val.Value), sanitizer.Replace(val.Display), sanitizer.Replace(val.Description))
 	}
 	return fmt.Sprintf("{\n%v\n}", strings.Join(vals, "\n"))
 }
diff --git a/internal/xonsh/snippet.go b/internal/xonsh/snippet.go
index 0f5b080..e673dbc 100644
--- a/internal/xonsh/snippet.go
+++ b/internal/xonsh/snippet.go
@@ -17,14 +17,24 @@ func Snippet(cmd *cobra.Command, actions map[string]string) string {
 
     from shlex import split
     from xonsh.completers.tools import RichCompletion
-    
-    full_words=split(line + "_") # ensure last word is empty when ends with space
-    full_words[-1]=full_words[-1][0:-1]
-    words=split(line[0:endidx] + "_") # ensure last word is empty when ends with space
+  
+    words=""
+    quoteLength = 0
+    try:
+        words=split(line[0:endidx] + "_") # ensure last word is empty when ends with space
+        if line[endidx-1] in ('"',"'"):
+            quoteLength = 2
+    except:
+        try:
+            words=split(line[0:endidx] + '"' + "_") # ensure last word is empty when ends with space
+            quoteLength = 1
+        except:
+            words=split(line[0:endidx] + "'" + "_") # ensure last word is empty when ends with space
+            quoteLength = 1
+
     words[-1]=words[-1][0:-1]
     current=words[-1]
     previous=words[-2]
-    suffix=full_words[len(words)-1][len(current):]
 
     result = {}
 
@@ -46,10 +56,15 @@ func Snippet(cmd *cobra.Command, actions map[string]string) string {
     if len(result) == 0:
         result = {RichCompletion(current, display=current, description='', prefix_len=0)}
 
-    result = set(map(lambda x: RichCompletion(x[:len(x)-(len(suffix)+suffix.count(' '))], display=x.display, description=x.description, prefix_len=len(current)+current.count(' ')), result))
+    def _%v_quote(s):
+        if " " in s:
+            return '"' + s + '"'
+        return s
+        
+    result = set(map(lambda x: RichCompletion(_%v_quote(x), display=x.display, description=x.description, prefix_len=len(current)+quoteLength), result))
     return result
 
 from xonsh.completers._aliases import _add_one_completer
 _add_one_completer('%v', _%v_completer, 'start')
-`, functionName, cmd.Name(), cmd.Name(), functionName, uid.Executable(), functionName, cmd.Name(), functionName)
+`, functionName, cmd.Name(), cmd.Name(), functionName, uid.Executable(), functionName, functionName, functionName, cmd.Name(), functionName)
 }


Test patch:
diff --git a/example/cmd/_test/xonsh.py b/example/cmd/_test/xonsh.py
index 18c217b..9517a46 100644
--- a/example/cmd/_test/xonsh.py
+++ b/example/cmd/_test/xonsh.py
@@ -5,14 +5,24 @@ def _example_completer(prefix, line, begidx, endidx, ctx):
 
     from shlex import split
     from xonsh.completers.tools import RichCompletion
-    
-    full_words=split(line + "_") # ensure last word is empty when ends with space
-    full_words[-1]=full_words[-1][0:-1]
-    words=split(line[0:endidx] + "_") # ensure last word is empty when ends with space
+  
+    words=""
+    quoteLength = 0
+    try:
+        words=split(line[0:endidx] + "_") # ensure last word is empty when ends with space
+        if line[endidx-1] in ('"',"'"):
+            quoteLength = 2
+    except:
+        try:
+            words=split(line[0:endidx] + '"' + "_") # ensure last word is empty when ends with space
+            quoteLength = 1
+        except:
+            words=split(line[0:endidx] + "'" + "_") # ensure last word is empty when ends with space
+            quoteLength = 1
+
     words[-1]=words[-1][0:-1]
     current=words[-1]
     previous=words[-2]
-    suffix=full_words[len(words)-1][len(current):]
 
     result = {}
 
@@ -34,7 +44,12 @@ def _example_completer(prefix, line, begidx, endidx, ctx):
     if len(result) == 0:
         result = {RichCompletion(current, display=current, description='', prefix_len=0)}
 
-    result = set(map(lambda x: RichCompletion(x[:len(x)-(len(suffix)+suffix.count(' '))], display=x.display, description=x.description, prefix_len=len(current)+current.count(' ')), result))
+    def _example_quote(s):
+        if " " in s:
+            return '"' + s + '"'
+        return s
+        
+    result = set(map(lambda x: RichCompletion(_example_quote(x), display=x.display, description=x.description, prefix_len=len(current)+quoteLength), result))
     return result
 
 from xonsh.completers._aliases import _add_one_completer