From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 27073 invoked from network); 19 Feb 2023 16:13:15 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 19 Feb 2023 16:13:15 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date:Content-ID: Content-Type:MIME-Version:Subject:To:References:From:In-reply-to:Reply-To:Cc: Content-Transfer-Encoding:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=zYU7ahHqq6aAXf40Vma7MqWu/c0YZv/HhpUOTunOhro=; b=UBtWIAkSwqtjWsljJCrFrZX5i6 DJhVjmisjoeVizK+PuJ5craDl0YD6+lf00j/BCHFcSKgS6ROEdJxlW9/pxLSndwlqRUNd8p5AV12M 1gPlLidy45e584Ey/Z1Et+JX6shT1rrkwayMlJhrIZhIgIpcVZGZIqOMXkWLIbrPhi1fP5bBk2zDp G7qhiQkJlQMlbFg2mhEQ6QN006eom1Y1AHOgl1x4Ioo+KCP4cYm6mxQyvwZonNjYxi0SKEgX/pD4Q 5YqlaZO1awo+EQrfo3qbyh4UyB88e8Ac8AfZWgGUPlRx31Wi2z9EIssnnj6I9I6lf3pgS37Z/Hqke 90gTovEw==; Received: by zero.zsh.org with local id 1pTmJN-0002UX-HB; Sun, 19 Feb 2023 16:13:13 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1pTmJ6-0002Bs-Ey; Sun, 19 Feb 2023 16:12:56 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.95) (envelope-from ) id 1pTmJ5-000KRk-4r for zsh-workers@zsh.org; Sun, 19 Feb 2023 17:12:55 +0100 In-reply-to: <89765-1676677636.286144@jiXR.VaXn.4CXW> From: Oliver Kiddle References: <89765-1676677636.286144@jiXR.VaXn.4CXW> To: Zsh workers Subject: Re: PATCH: complete ldap search filters MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <78598.1676823175.1@hydra> Date: Sun, 19 Feb 2023 17:12:55 +0100 Message-ID: <78599-1676823175.147342@t7nh.QcFd.gdPV> X-Seq: 51461 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: 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)^"$(]|)=/' ':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 ))' \) \# )