zsh-users
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: TJ Luoma <luomat@gmail.com>
Cc: Zsh MailingList <zsh-users@zsh.org>
Subject: Re: completion for function arguments?
Date: Thu, 8 Aug 2019 17:42:48 +0200	[thread overview]
Message-ID: <CAHYJk3RnF4d63SgbdHmL0qsCV-Fttc8WqWq9P6QQBpnH=hm3Pw@mail.gmail.com> (raw)
In-Reply-To: <CADjGqHu2c=s8wk_wkrMEX4OdJOtWTNuCDnBynXgESYhjBiNdBQ@mail.gmail.com>

On 8/8/19, TJ Luoma <luomat@gmail.com> 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

      parent reply	other threads:[~2019-08-08 20:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-08 13:06 TJ Luoma
2019-08-08 13:49 ` Jérémie Roquet
2019-08-08 15:42 ` Mikael Magnusson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHYJk3RnF4d63SgbdHmL0qsCV-Fttc8WqWq9P6QQBpnH=hm3Pw@mail.gmail.com' \
    --to=mikachu@gmail.com \
    --cc=luomat@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).