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:
xonsh: fix begidx for quoted values
fixes #199 

Patch:
diff --git a/internal/xonsh/snippet.go b/internal/xonsh/snippet.go
index e673dbc..be1e08a 100644
--- a/internal/xonsh/snippet.go
+++ b/internal/xonsh/snippet.go
@@ -19,20 +19,28 @@ func Snippet(cmd *cobra.Command, actions map[string]string) string {
     from xonsh.completers.tools import RichCompletion
   
     words=""
-    quoteLength = 0
+    wordsNonPosix=""
     try:
         words=split(line[0:endidx] + "_") # ensure last word is empty when ends with space
-        if line[endidx-1] in ('"',"'"):
-            quoteLength = 2
+        wordsNonPosix=split(line[0:endidx], posix=False)
     except:
         try:
             words=split(line[0:endidx] + '"' + "_") # ensure last word is empty when ends with space
-            quoteLength = 1
+            wordsNonPosix=split(line[0:endidx] + '"', posix=False)
+            wordsNonPosix[-1]= wordsNonPosix[-1][:-1]
         except:
             words=split(line[0:endidx] + "'" + "_") # ensure last word is empty when ends with space
-            quoteLength = 1
-
+            wordsNonPosix=split(line[0:endidx] + "'", posix=False)
+            wordsNonPosix[-1]= wordsNonPosix[-1][:-1]
+    
     words[-1]=words[-1][0:-1]
+    if len(words[-1]) != 0:
+        begidx = endidx
+        for word in reversed(wordsNonPosix):
+            begidx = begidx - len(word)
+            if line[begidx-1] == " ":
+                break
+
     current=words[-1]
     previous=words[-2]
 
@@ -61,10 +69,10 @@ func Snippet(cmd *cobra.Command, actions map[string]string) string {
             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))
+    result = set(map(lambda x: RichCompletion(_example_quote(x), display=x.display, description=x.description, prefix_len=endidx-begidx), 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, functionName, functionName, cmd.Name(), functionName)
+`, functionName, cmd.Name(), cmd.Name(), functionName, uid.Executable(), functionName, functionName, cmd.Name(), functionName)
 }


Test patch:
diff --git a/example/cmd/_test/xonsh.py b/example/cmd/_test/xonsh.py
index 9517a46..92969ae 100644
--- a/example/cmd/_test/xonsh.py
+++ b/example/cmd/_test/xonsh.py
@@ -7,20 +7,28 @@ def _example_completer(prefix, line, begidx, endidx, ctx):
     from xonsh.completers.tools import RichCompletion
   
     words=""
-    quoteLength = 0
+    wordsNonPosix=""
     try:
         words=split(line[0:endidx] + "_") # ensure last word is empty when ends with space
-        if line[endidx-1] in ('"',"'"):
-            quoteLength = 2
+        wordsNonPosix=split(line[0:endidx], posix=False)
     except:
         try:
             words=split(line[0:endidx] + '"' + "_") # ensure last word is empty when ends with space
-            quoteLength = 1
+            wordsNonPosix=split(line[0:endidx] + '"', posix=False)
+            wordsNonPosix[-1]= wordsNonPosix[-1][:-1]
         except:
             words=split(line[0:endidx] + "'" + "_") # ensure last word is empty when ends with space
-            quoteLength = 1
-
+            wordsNonPosix=split(line[0:endidx] + "'", posix=False)
+            wordsNonPosix[-1]= wordsNonPosix[-1][:-1]
+    
     words[-1]=words[-1][0:-1]
+    if len(words[-1]) != 0:
+        begidx = endidx
+        for word in reversed(wordsNonPosix):
+            begidx = begidx - len(word)
+            if line[begidx-1] == " ":
+                break
+
     current=words[-1]
     previous=words[-2]
 
@@ -49,7 +57,7 @@ def _example_completer(prefix, line, begidx, endidx, ctx):
             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))
+    result = set(map(lambda x: RichCompletion(_example_quote(x), display=x.display, description=x.description, prefix_len=endidx-begidx), result))
     return result
 
 from xonsh.completers._aliases import _add_one_completer