From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 1ebaf25f for ; Wed, 20 Mar 2019 02:06:10 +0000 (UTC) Received: (qmail 18099 invoked by alias); 20 Mar 2019 02:05:51 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 44144 Received: (qmail 23311 invoked by uid 1010); 20 Mar 2019 02:05:51 -0000 X-Qmail-Scanner-Diagnostics: from mail-oi1-f179.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.100.2/25391. spamassassin: 3.4.2. Clear:RC:0(209.85.167.179):SA:0(-1.8/5.0):. Processed in 1.198091 secs); 20 Mar 2019 02:05:51 -0000 X-Envelope-From: phy1729@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.167.179 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mail-followup-to:mime-version :content-disposition:user-agent; bh=wBB4xpTFvvBXRl36Twc2rYmm5DdxGbVWa70HdXAJ5kw=; b=UPBestwlvCpgxmhRgMFSRv117PBEAGK/xJ+fJvsFqbPrIhkuY/zJu/BuCv3g6iGPj8 MleIfnv9kdBHETw0OvgJDHocglp+k+4K9aHYgY0OX/210hrOfOQZwKzd73cCu7Cv2tA2 heX/w5IjOTHzOyHWeDV7UXAGNJUOG3kGaRHpejPx4vlaMwTu13b8x9D8in6YqPXb4UhN 1kp1ENqM25/RI28faQ80Crk1m1gectjGsz1sfLe3a7yXRMlyxQB1GQJEbwD64AmzXvqu 6vFGC/lWklyjJ5y+z6jb51m4tGjx3tdC18ipzuCPpmsWrm5T548u/qzJ9ZUZW0Vvoc9t FH8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :mime-version:content-disposition:user-agent; bh=wBB4xpTFvvBXRl36Twc2rYmm5DdxGbVWa70HdXAJ5kw=; b=rnojTtFO5Gl1Bb3PNcc48+Xz+zISYVBUU9JKqRi0DSSxn57TgymtBmFgdgd24f8Ng0 qFoLniHogy23dZVczwNMBpNilzXLd0hYA9//izC5lK8drxFqcPVx22mYZcDTi6sts8/n jY5ZfgICgNpuDoexZHpQUYLtl/OlKmrqHOTohCOTW4tkN+vrnsJONPhVZAtWJL3uzpg9 ca3EpmR6E3dceVRys037JCCBvY/hinsu7v/hFIr+L5DhnS104Nc1tL+APpg4iHaZlLaq q6Bur+x+rYnGRsxJnH+9FUugBY+Np5vYLFcbkI5dZCwVAgbx0I7qj3FZ1nVGWogKekwG 94Tw== X-Gm-Message-State: APjAAAU6pv4rJfHWc03Us+G6JlvwoYrt2IJb0HqevA5MjEuSsS5Aq66e BpHO7AUx/iCvBz6fkzyW9EgfzTPw X-Google-Smtp-Source: APXvYqyeSm7csAgXtbmeFdPCrLOucFzTCqsdXuL6LVgmm0DmuhA7BDwoyPz3qPx2DtOMYEXt/NYmgQ== X-Received: by 2002:aca:3ac5:: with SMTP id h188mr3322284oia.11.1553047515802; Tue, 19 Mar 2019 19:05:15 -0700 (PDT) Date: Tue, 19 Mar 2019 21:05:13 -0500 From: Matthew Martin To: zsh-workers@zsh.org Subject: [PATCH] _pick_variant: Update builtin check Message-ID: <20190320020511.GA6739@CptOrmolo.darkstar> Mail-Followup-To: zsh-workers@zsh.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.11.4 (2019-03-13) Move the builtin check prior to the cache lookup and don't cache builtins if -b is provided. This corrects the result if a user uses both a builtin and external version of a command in one shell session. The command may be builtin only if all precommands are builtin-preserving which are enumerated in builtin_precommands. Since a builtin-preserving precommand must be itself builtin, I figure it's easier to maintain as a white list. This corrects the case Daniel brought up: command chmod . I'll split out the _builtin change before commit. Wasn't large enough to get its own mail but necessary if anyone is testing. - Matthew Martin --- Completion/Base/Utility/_pick_variant | 15 +++++++++------ Completion/Zsh/Command/_builtin | 2 ++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Completion/Base/Utility/_pick_variant b/Completion/Base/Utility/_pick_variant index 9099e3599..f4ceb7462 100644 --- a/Completion/Base/Utility/_pick_variant +++ b/Completion/Base/Utility/_pick_variant @@ -1,9 +1,11 @@ #autoload local output cmd pat -local -a var +local -a builtin_precommands var local -A opts +builtin_precommands=(- builtin eval exec nocorrect noglob time) + (( $+_cmd_variant )) || typeset -gA _cmd_variant zparseopts -D -A opts b: c: r: @@ -13,15 +15,16 @@ while [[ $1 = *=* ]]; do var+=( "${1%%\=*}" "${1#*=}" ) shift done -if (( $+_cmd_variant[$opts[-c]] )); then - (( $+opts[-r] )) && eval "${opts[-r]}=${_cmd_variant[$opts[-c]]}" - [[ $_cmd_variant[$opts[-c]] = "$1" ]] && return 1 + +if (( $+opts[-b] && ! ${#precommands:|builtin_precommands} && + ( $+builtins[$opts[-c]] || $precommands[(I)builtin] ) )); then + (( $+opts[-r] )) && eval "${opts[-r]}=$opts[-b]" return 0 fi -if [[ $+opts[-b] -eq 1 && -n $builtins[$opts[-c]] ]]; then - _cmd_variant[$opts[-c]]=$opts[-b] +if (( $+_cmd_variant[$opts[-c]] )); then (( $+opts[-r] )) && eval "${opts[-r]}=${_cmd_variant[$opts[-c]]}" + [[ $_cmd_variant[$opts[-c]] = "$1" ]] && return 1 return 0 fi diff --git a/Completion/Zsh/Command/_builtin b/Completion/Zsh/Command/_builtin index 9fb6acf7b..a77af9879 100644 --- a/Completion/Zsh/Command/_builtin +++ b/Completion/Zsh/Command/_builtin @@ -1,5 +1,7 @@ #compdef builtin +precommands+=(builtin) + if (( $CURRENT > 2 )); then shift words (( CURRENT -- )) -- 2.21.0