Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Patch 3/3: Fix subscript completion bugs inside ~[...]




From 150b4cdac452e06a2ae38e5ba922f84636f2fcf7 Mon Sep 17 00:00:00 2001
From: Marlon Richert <marlon.richert@xxxxxxxx>
Date: Sat, 29 Apr 2023 20:58:54 +0300
Subject: [PATCH 3/3] Fix subscript completion bugs inside ~[...]

* _main_complete was exited prematurely, causing essential completion
  features, such as _setup and comppostfuncs, to be skipped.
* Subscript completion was skipped when there were one or more slashes
  ('/') in the subscript.
---
 Completion/Base/Core/_main_complete | 22 +++++++++-------------
 Test/Y01completion.ztst             | 16 +++++++++++++---
 2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/Completion/Base/Core/_main_complete b/Completion/Base/Core/_main_complete
index 169ca1f40..408a66ee3 100644
--- a/Completion/Base/Core/_main_complete
+++ b/Completion/Base/Core/_main_complete
@@ -93,19 +93,15 @@ fi
 if [[ -z "$compstate[quote]" ]]; then
   if [[ -o equals ]] && compset -P 1 '='; then
     compstate[context]=equal
-  elif [[ "$PREFIX" != */* && "$PREFIX[1]" = '~' ]]; then
-    if [[ "$PREFIX" = '~['[^\]]# ]]; then
-      # Inside ~[...] should be treated as a subscript.
-      compset -p 2
-      # To be consistent, we ignore all but the contents of the square
-      # brackets.
-      compset -S '\]*'
-      compstate[context]=subscript
-      [[ -n $_comps[-subscript-] ]] && $_comps[-subscript-] && return
-    else
-      compset -p 1
-      compstate[context]=tilde
-    fi
+  elif [[ "$PREFIX" = \~\[[^]]# ]]; then
+    # Inside ~[...] should be treated as a subscript.
+    compset -p 2
+    # To be consistent, we ignore all but the contents of the square brackets.
+    compset -S '\]*'
+    compstate[context]=subscript
+  elif [[ "$PREFIX" = \~[^/]# ]]; then
+    compset -p 1
+    compstate[context]=tilde
   fi
 fi
 
diff --git a/Test/Y01completion.ztst b/Test/Y01completion.ztst
index 2524c43bd..693ea7d58 100644
--- a/Test/Y01completion.ztst
+++ b/Test/Y01completion.ztst
@@ -93,17 +93,27 @@
 >line: {: ~user2}{}
 >line: {: ~user1}{}
 
-  comptesteval 'zsh_directory_name() { compadd "$expl[@]" -- name1 name2 }'
+  comptesteval 'zsh_directory_name() { compadd "$expl[@]" -- name/1 name2 }'
   comptest $': ~[\t\t\t\t'
 0:dynamic directory names after ~[
 >line: {: ~[name}{}
 >line: {: ~[name}{}
 >DESCRIPTION:{dynamically named directory}
->NO:{name1}
+>NO:{name/1}
 >NO:{name2}
->line: {: ~[name1]}{}
+>line: {: ~[name/1]}{}
 >line: {: ~[name2]}{}
 
+  comptest $': ~[]\C-b\t\t\t\t'
+0:dynamic directory names inside ~[...]
+>line: {: ~[name}{]}
+>line: {: ~[name}{]}
+>DESCRIPTION:{dynamically named directory}
+>NO:{name/1}
+>NO:{name2}
+>line: {: ~[name/1}{]}
+>line: {: ~[name2}{]}
+
   comptest $'echo ;:\C-b\C-b\t'
 0:directories and files before separator
 >line: {echo }{;:}
-- 
2.39.2 (Apple Git-143)



Messages sorted by: Reverse Date, Date, Thread, Author