Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: complete ldap search filters
- X-seq: zsh-workers 51461
- From: Oliver Kiddle <opk@xxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxx>
- Subject: Re: PATCH: complete ldap search filters
- Date: Sun, 19 Feb 2023 17:12:55 +0100
- Archived-at: <https://zsh.org/workers/51461>
- In-reply-to: <89765-1676677636.286144@jiXR.VaXn.4CXW>
- List-id: <zsh-workers.zsh.org>
- References: <89765-1676677636.286144@jiXR.VaXn.4CXW>
I wrote:
> This adds a helper function for completing LDAP search filters
> It still needs some adapting to work properly with backslash quoting.
This further patch gets the quoting right. The completion system will
sometimes remove backslash quoting on ! which isn't helpful with
bang-history enabled. Ideally, _regex_arguments would let you do
matching against the unquoted form by supporting some sort of compset
-q.
The function ignores & (AND) and | (OR) operators where you would be
nesting them directly. It occurred to me that it should also do the same
for ! (NOT) - it's even more obvious why that's pointless.
Oliver
diff --git a/Completion/Unix/Type/_ldap_filters b/Completion/Unix/Type/_ldap_filters
index 919f9e266..5e0e30f01 100644
--- a/Completion/Unix/Type/_ldap_filters
+++ b/Completion/Unix/Type/_ldap_filters
@@ -4,7 +4,7 @@
local -a expl excl optype disp end pre
local -i nest=0
-local open='(' close=')'
+local open='(' close=')' andop='&' orop='|'
[[ -prefix - ]] && return 1
@@ -40,25 +40,25 @@ local -a classes=( # Sampled from real servers, arbitrary other values allowed
shadowAccount simpleSecurityObject top
)
-compquote open close
+compquote open close andop orop
open=${(q)open} close=${(q)close}
# default to double rather than backslash quoting
-[[ -z $compstate[quote] || -z $PREFIX ]] && pre='"('
+[[ -z $compstate[quote] && -z $PREFIX ]] && pre='"('
zstyle -s ":completion:${curcontext}:operators" list-separator sep || sep=--
print -v disp -f "%s $sep %s" \| or \& and \! not
end=( ") $sep end" )
-excl=( \\\| \& ) # compadd -F uses globs: only | needs quoting
+excl=( ! \\\| \& ) # compadd -F uses globs: only | needs quoting
local -a query=(
\( /$'*\0[ \t\n]#'/ \) # strip off any preceding arguments
\(
- \( "/${open}!/" -'optype[++nest]=0;pre=""'
- \| "/${open}\|/" -'optype[++nest]=1;pre=""'
- \| "/${open}&/" -'optype[++nest]=2;pre=""'
- \| '/[]/' ':operators:operator:compadd -F "( ${(q)excl[optype[nest]]} )" -d disp -P ${pre:-${(Q)open}} -S \( \| \& \!' \)
+ \( "/${open}!/" -'optype[++nest]=1;pre=""'
+ \| "/${open}${(q)orop}/" -'optype[++nest]=2;pre=""'
+ \| "/${open}${andop}/" -'optype[++nest]=3;pre=""'
+ \| '/[]/' ':operators:operator:compadd -F "( ${(q)excl[optype[nest]]} )" -d disp -P ${pre:-${(Q)open}} -S ${(Q)open} \| \& \!' \)
\|
- \( '/[^)]##/' '%\)%' # pass over whole var=value, needed due to lack of backtracking after the following
+ \( "/${open}[^\\)]##/" "%$close%" # pass over whole var=value, needed due to lack of backtracking after the following
\| "/${open}(#i)homeDirectory=/" '/[]/' ':directories:directory:_directories -P / -W / -r ") \t\n\-"'
\| "/${open}(#i)loginShell=/" '/[]/' ':shells:shell:compadd -S ${(Q)close} ${(f)^"$(</etc/shells)"}(N)'
\| "/${open}(#i)mail=/" '/[]/' ':email-addresses:mail:_email_addresses -S ${(Q)close}'
@@ -74,7 +74,7 @@ local -a query=(
\|
'/([~<>]|)=/' ':operators:operator:compadd -S "" "<=" \>= \~='
\)
- '/[^)]##/' '%\)%' ': _message -e object-values "object value (* for presence check)"'
+ '/[^\\)]##/' "%$close%" ': _message -e object-values "object value (* for presence check)"'
\)
"/$close/" -'(( nest ))' ':brackets:bracket:compadd ${=query[nest]:+-S ""} \)'
\(
@@ -83,7 +83,7 @@ local -a query=(
"/$close/" ':operators:operator:compadd ${=query[nest-1]:+-S ""} -d end -P ${(Q)close} ""'
\( // -'(( --nest ))' \| '//' -'((!nest))' '/[]/' ': compadd ""' \)
\) \#
- // -'(( nest && optype[nest] ))'
+ // -'(( nest && optype[nest] > 1 ))'
\) \#
)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author