1

I have a small script for managing tickets in gitlab repos. When I type ticket and press tab, I'd like to see:

% ticket
new  -- create a new ticket
#    -- Number of ticket
-v   -- increase verbosity

To do this I've done this which doesn't work:

#compdef ticket
#autoload

local -a reply

_regex_words commands "ticket commands" \
  'new:create a new ticket' \
  '-v:increase verbosity' \
  '[1-9][0-9]#:open ticket #'
_regex_arguments _ticket /$'[^\0]##\0'/ "${reply[@]}"

_ticket "$@"

I get that it can't complete the number in my brain - nor do I want it going out and loading up possibly thousands of numbers. But noting that a number is a possible completion would be good.

1 Answer 1

1

The _regex_words function is meant for use with literal words, not with patterns (aside from a single * where words can be abbreviated). So you'll need to handle the number from _regex_arguments directly – something like the following:

#compdef ticket

local -a reply

_regex_words commands "ticket commands" \
  'new:create a new ticket' \
  '-v:increase verbosity'

_regex_arguments _ticket /$'[^\0]##\0'/ \
  \( "${reply[@]}" \
  \| $'/[1-9][0-9]#\0/' ': _message -e numbers "open ticket"' \)

_ticket "$@"

It's a bit ugly that this needs _message. That's a side-effect of how it is implemented via _alternative but there are examples of this style elsewhere. If you've got many normal options like -v, it can be better to use _arguments for those and only use _regex_arguments for more complicated areas.

By the way, you #autoload tag is superfluous. compinit looks at the first line only and either #autoload or #compdef will cause it to be marked as autoloadable.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .