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 e2214d71 for ; Thu, 8 Aug 2019 20:19:14 +0000 (UTC) Received: (qmail 9974 invoked by alias); 8 Aug 2019 15:43:25 -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: List-Unsubscribe: X-Seq: 24137 Received: (qmail 10883 invoked by uid 1010); 8 Aug 2019 15:43:24 -0000 X-Qmail-Scanner-Diagnostics: from mail-ot1-f46.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.101.2/25531. spamassassin: 3.4.2. Clear:RC:0(209.85.210.46):SA:0(-2.0/5.0):. Processed in 2.140989 secs); 08 Aug 2019 15:43:24 -0000 X-Envelope-From: mikachu@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.210.46 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=M/Ae5TXaGifQxb5B/Do1APmW9a8MuwfGWqGVINOV8Lg=; b=E1tl+o3wjNDhSlRE0E7SUKTM18QC7Kg4RvKhR3f27S6OseTiXpBQNqAo2Xq4CET7Yv nVzubOpOVskgzf5rBYFs0lZIYIqBwb6x+9CViILZKKYThTdhlmrLj23Rm7hPVj0T/OEF z8msUpX7Yxns0HPzUPzbBrhhApXLwSBgLs2M+s1A/h/356ijAWHmNm+7dagE8gGpH3TN gWMljNqITrrZ4DSeP3lC8y8zkFPTYdQGs+zpyBY0GizUiWpKRbJk23dhum4bjBWI2RzI VYGbDF5Kvlgw8hSAJ/HYp0z8sMmWOsvdzXFCPG/7ZAs7XJxAprex/uko8Hf49LIWGRfv iV2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=M/Ae5TXaGifQxb5B/Do1APmW9a8MuwfGWqGVINOV8Lg=; b=OXp+jRc1i0ZUwWMOtxheuHEA3z4Z51Y+17pu5hgCmUN5x+P9vXH8ZzQifOLW2wuNjY ICj9dKq2VoTjL4cLuI5v/CWJliVki+JlxrFJu/9f20FxxjiCdZYj+D8evsP1WmtzX76z 01qrlG2FSjQ36Gt3lxuJyXfEW8sSLm6SYmARORPLTR0J3VheABfVhjb4+6AsJLQUtjYb wRkYm+CDbjKgO/B5W55Bd5OIrOvjmbnkpSbHE1LUhL+16IvXx5WcCGzIx3x9z0KzqKWQ jHHMBhYsUH6ul9ayD/+LMCFmWScezppM14hRlNGTM73LPfZQuo+LWy8vT5gaELOzRznx FS1g== X-Gm-Message-State: APjAAAUvxvn4qIG1tZMrDEGIk+REguIscrDKL01MiRw+2SAzQKPdJNI/ kqi2i7ggVCoq1ilVN71agKJqMh5I3cTTPy7hOFs= X-Google-Smtp-Source: APXvYqzP/U344HObClqI8nSHtY1EWwGDbZOv6UGU642jC6OBeIWEi4X2woQrSIqYPPPF/ICUuNaAPqbMSY8yCr+VogA= X-Received: by 2002:a5d:8d15:: with SMTP id p21mr15116208ioj.219.1565278969069; Thu, 08 Aug 2019 08:42:49 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Mikael Magnusson Date: Thu, 8 Aug 2019 17:42:48 +0200 Message-ID: Subject: Re: completion for function arguments? To: TJ Luoma Cc: Zsh MailingList Content-Type: text/plain; charset="UTF-8" On 8/8/19, TJ Luoma wrote: > Let me start by saying that I don't understand completion at all, so > this may be a) simple or b) impossible or c) have to be done a > completely different way. > > I have a function called 'jump' which I will include below. > > The function takes one (1) argument from a specific list of arguments. > I have defined these arguments as part of the function, although they > don't have to be defined that way if there's another way of doing it > that would work better for completion. [snip] > As you can see, these files are obscurely named in an obscure folder > on my Mac, but I _could_ create links to all of them with the > preferred names, such as > > ~/jump/m1 > ~/jump/mini > ~/jump/mba > ~/jump/tyrion > ~/jump/imac > > and then all the function would need to do is open the file that > matches the argument. > > I'd like to be able to type "jump [tab]" and have all of the options > appear (m1, mini, mba, tyrion, imac) or type "jump m[tab]" and have > just the ones that start with 'm' appear, etc. I think that's all > fairly standard completion stuff. > > Any help would be appreciated. For a very quick and dirty solution, dump this in your .zshrc compdef -e '() { local expl; _wanted jump-targets expl "jump target" compadd m1 mini mba tyrion imac }' jump The next step up is to create a file called _jump, put it in your $fpath and ensure fpath is set correctly before calling compinit, and then the contents of that file would be: #compdef jump local expl _wanted jump-targets expl "jump target" compadd m1 mini mba tyrion imac And of course from here you can get more fancy with generating the list of targets. For any more complex handling, ie if jump were to support some --options and multiple arguments, you would probably want to start using _arguments instead. -- Mikael Magnusson