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

PATCH: One small step towards making ~[foo]<tab> work



I'm not sure if the first hunk does anything useful, because I'm unable
to make much else after that work yet. The second hunk at least makes it
so ~[foo/]/ tries ~[foo/] as the prefix instead of ~[foo. This results
in ~[m48/]<tab> completing to files inside the directory I want but,
it lists it as "corrections (errors: 1)". Doing ~[m48/]/<tab> produces a
"no match" error.

~[m48]<tab> still produces nonsense results like ~man ~messagebus etc,
I guess it thinks [m48] is a character class. I don't know where to hook
into that properly to redirect it to _path_files(?).

(The %%]*] is not strictly correct, zsh currently accepts
~[foo]blabla/hello as an expansion to bazblabla/hello if ~[foo] expands
to baz, which is possibly not something we should allow. It feels weird
anyway).

---
 Completion/Base/Completer/_expand | 1 +
 Completion/Unix/Type/_path_files  | 7 ++++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/Completion/Base/Completer/_expand b/Completion/Base/Completer/_expand
index 3c76e13..1c25238 100644
--- a/Completion/Base/Completer/_expand
+++ b/Completion/Base/Completer/_expand
@@ -45,6 +45,7 @@ if [[ "$tmp" != (yes|true|on|1) ]]; then
   { [[ "$word" = \~(|[-+]) ||
        ( "$word" = \~[-+][1-9]## && $word[3,-1] -le $#dirstack ) ]] && return 1 }
   { [[ ( "$word" = \~* && ${#userdirs[(I)${word[2,-1]}*]}+${#nameddirs[(I)${word[2,-1]}*]} -gt 1 ) ||
+       ( "$word" = \~\[* ) ||
        ( "$word" = *\$[a-zA-Z0-9_]## && 
          ${#parameters[(I)${word##*\$}*]} -ne 1 ) ]] && continue=1 }
   [[ continue -eq 1 && "$tmp" != continue ]] && return 1
diff --git a/Completion/Unix/Type/_path_files b/Completion/Unix/Type/_path_files
index fc5bdac..f51db4a 100644
--- a/Completion/Unix/Type/_path_files
+++ b/Completion/Unix/Type/_path_files
@@ -283,7 +283,12 @@ elif [[ "$pre[1]" = \~ && -z "$compstate[quote]" ]]; then
   # paths and make sure that the loop below is run only once with an empty
   # prefix path by setting `prepaths'.
 
-  linepath="${pre[2,-1]%%/*}"
+  linepath="${pre[2,-1]}"
+  if [[ "$linepath" = \[* ]]; then
+    linepath="${linepath%%]*}]"
+  else
+    linepath="${linepath%%/*}"
+  fi
   if [[ -z "$linepath" ]]; then
     realpath="${HOME%/}/"
   elif [[ "$linepath" = ([-+]|)[0-9]## ]]; then
-- 
2.4.0



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