From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13028 invoked by alias); 12 Mar 2017 22:27:17 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 22561 Received: (qmail 15408 invoked from network); 12 Mar 2017 22:27:16 -0000 X-Qmail-Scanner-Diagnostics: from mail-ua0-f178.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.217.178):SA:0(0.5/5.0):. Processed in 1.916506 secs); 12 Mar 2017 22:27:16 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.5 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_SORBS_SPAM,SPF_PASS, T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.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.217.178 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=HmsQXq+HYDVQHPEXN0oP781NSeD9e/bXqjOKXw12ans=; b=H50l6ayZrnqvvYH86u6kb1dyPBSis0BIUerY7Lmf195Dj5JIjwzrfd8VRP11qM1qNO Edj3UzIOx+b5GlBIMjTDmZNShb4gJnsRF1VuL1MsWnn6qtpW5MgCjMVFAJ6SNTMHF6ZC j+wOateYjxkOPs8bKv1Cgk1RS8jrpCuXDMEBlX4iLB6cpp78ozf8Km8+pMdAY2znh1ds QeLSUgIT3IlFvNLql2c451P4Mw8ncQ7O8+LdElBck3MTiSkGwv9XyL4Wh0nMlVab16GC 4tYAYuAT2dhXW7Skm+gTMr/8Q18k2z6nBJCX9ZysXoF3YXls3Octt/DQ96/252eKD1tW J76g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version; bh=HmsQXq+HYDVQHPEXN0oP781NSeD9e/bXqjOKXw12ans=; b=LvXzdGP5yXH8p3ESr+WrDcFpoZjng/8G/Jtv5meii11hMjIupXUjh5wsFS3lWje4GE ozjmF/OsnKhr5ccgipJ9IySlndFjNbBL6/2Ni5usuNYYOCB6v0PvQrMVaMzwCG4Vea4I lMP81TZV30T4zM/E3Y3HjNBAAVNySgJ4M3aLtGbdjjyv1UI5uyIF1SAKZE9rsai2nyPw kx9d6pC4ZuP3RGCLCuCYvxqSiHjfrHSsRseXcbgAWxN/AHHxo46XRPxW811hoODFb7oD hitWxJ+c6dtG9fSVWa7QWgI2yHjJiP/RNmGHImkktT4An/GT4pbfzYdyWj8XE0Bay0nC 0Bow== X-Gm-Message-State: AMke39k2+UwQcrUq8v5uvCbbxUWr8PS1yMv/P77zIC8YZjOKTAiwV4b1PaLY9svjkGg2+w== X-Received: by 10.159.49.87 with SMTP id n23mr11869452uab.134.1489357625255; Sun, 12 Mar 2017 15:27:05 -0700 (PDT) From: Bart Schaefer Message-Id: <170312152742.ZM16252@torch.brasslantern.com> Date: Sun, 12 Mar 2017 15:27:42 -0700 In-Reply-To: <5fe1f6a0-a0d1-9b21-310c-a3bb16aa7d18@thequod.de> Comments: In reply to Daniel Hahler "Setup git-stash completion for a function: $line is wrong" (Mar 12, 5:37pm) References: <5fe1f6a0-a0d1-9b21-310c-a3bb16aa7d18@thequod.de> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: Setup git-stash completion for a function: $line is wrong MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Mar 12, 5:37pm, Daniel Hahler wrote: } } I am using a helper method to setup completion for functions that are } used as extended aliases. } } # Helper to setup completion for functions, e.g. } # "complete_function gcf git commit --fixup" will setup completion for } # "gcf" => "git commit --fixup". } complete_function() { } local f=$1; shift } compdef -e "words=($* \"${(@)words[2,-1]}\"); ((CURRENT+=$(( $#*-1 )))); _normal" $f } } This can't be right. Because of the double quotes around the argument of compdef -e, ${(@)words[2,-1]} will expand when complete_function is executed, not when the compdef value is needed. Same for $(( $#*-1 )) which by the way is the same as $(( $# - 1 )). Also as you are already inside (( )) you don't need $(( )). Try it this way: complete_function() { local f=$1; shift compdef -e "words[1]=( ${${(qq)@}} ); (( CURRENT += $# )); _normal" $f } There's a bit of magic there using an extra ${...} around ${(qq)@} to force the multi-word expansion of $@ back into a single string so that the outer double-quotes won't split it the way "$@" is normally split. } Additionally, I think that zsh itself should provide a way to more } easily setup completion for functions (i.e. something like my wrapper } function above). How would you envision this to work? How does "zsh itself" know what someone is going to do inside a function body? There's already (compdef cmd=service) e.g. compdef gsta=git for wrappers that don't insert things into their argument words to act exactly like a pre-existing completion. Also, using an alias instead of a function wrapper, i.e., alias gsta='git stash' should "just work" because completion will expand the alias before it builds $words and looks up the completion.