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

[FEATURE][PATCH] Complete local executables with ./ prefix, if prefix-needed is false



This allows local executables to be completed more easily, without the
need for . in $path.
From 6edea832ff20aa31852042286cdba3602f8cd527 Mon Sep 17 00:00:00 2001
From: Marlon Richert <marlonrichert@xxxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 7 Dec 2021 21:07:53 +0200
Subject: [PATCH] Complete local executables with ./ prefix, if prefix-needed
 is false

This allows local executables to be completed more easily, without the need for . in $path.
---
 Completion/Zsh/Type/_command_names | 15 +++++++++------
 Doc/Zsh/compsys.yo                 |  5 ++++-
 Test/Y01completion.ztst            | 11 +++++++++++
 3 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/Completion/Zsh/Type/_command_names b/Completion/Zsh/Type/_command_names
index b1c35f013..68df9522b 100644
--- a/Completion/Zsh/Type/_command_names
+++ b/Completion/Zsh/Type/_command_names
@@ -8,16 +8,15 @@ local args defs ffilt
 
 zstyle -t ":completion:${curcontext}:commands" rehash && rehash
 
-zstyle -t ":completion:${curcontext}:functions" prefix-needed && \
- [[ $PREFIX != [_.]* ]] && \
- ffilt='[(I)[^_.]*]'
-
 defs=(
   'commands:external command:_path_commands'
 )
 
-[[ -n "$path[(r).]" || $PREFIX = */* ]] &&
-    defs+=( 'executables:executable file:_files -g \*\(-\*\)' )
+if [[ -n "$path[(r).]" || $PREFIX = */* ]]; then
+  defs+=( 'executables:executable file:_files -g \*\(-\*\)' )
+elif ! zstyle -T ":completion:${curcontext}:executables" prefix-needed; then
+  defs+=( 'executables:executable file:_files -g ./\*\(-\*\)' )
+fi
 
 if [[ "$1" = -e ]]; then
   shift
@@ -26,6 +25,10 @@ elif (( ${#precommands:|builtin_precommands} )); then
 else
   [[ "$1" = - ]] && shift
 
+zstyle -t ":completion:${curcontext}:functions" prefix-needed && \
+    [[ $PREFIX != [_.]* ]] && \
+        ffilt='[(I)[^_.]*]'
+
   defs=( "$defs[@]"
     'builtins:builtin command:compadd -Qk builtins'
     "functions:shell function:compadd -k 'functions$ffilt'"
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index f85293ac7..6f04b8ea8 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -2414,7 +2414,7 @@ set to `true' this common prefix must be typed by the user to generate
 the matches.
 
 The style is applicable to the tt(options), tt(signals), tt(jobs),
-tt(functions), and tt(parameters) completion tags.
+tt(executables), tt(functions) and tt(parameters) completion tags.
 
 For command options, this means that the initial `tt(-)', `tt(+)', or
 `tt(-)tt(-)' must be typed explicitly before option names will be
@@ -2426,6 +2426,9 @@ be completed.
 For jobs, an initial `tt(%)' is required before job names will be
 completed.
 
+For executables, an initial `tt(./)' is required before executables that are in
+the current dir (but not in var($path)) will be completed.
+
 For function and parameter names, an initial `tt(_)' or `tt(.)' is
 required before function or parameter names starting with those
 characters will be completed.
diff --git a/Test/Y01completion.ztst b/Test/Y01completion.ztst
index 6af0efc6d..8ff00af6f 100644
--- a/Test/Y01completion.ztst
+++ b/Test/Y01completion.ztst
@@ -266,6 +266,17 @@ F:regression test workers/31611
 >FI:{file1}
 >FI:{file2}
 
+  chmod u+x file1 file2
+  comptesteval 'zstyle ":completion:*:executables" prefix-needed no'
+  comptesteval 'zstyle ":completion:*" tag-order executables'
+  comptesteval 'zstyle ":completion:*" matcher-list "l:|=*"'
+  comptest $'f\C-D'
+0:list local executables with ./ prefix, if prefix-needed is false
+>DESCRIPTION:{executable file}
+>EX:{./file1}
+>EX:{./file2}
+
+  comptesteval 'zstyle -d ":completion:*" matcher-list'
   comptesteval "typeset -a bar=({$'\\0'..$'\\C-?'})"
   comptesteval 'typeset -A bat=( "$bar[@]" )'
   comptesteval 'typeset bay="$bar"'
-- 
2.33.0



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