zsh-users
 help / color / Atom feed
* how to debug completion or: how to change _arguments depending on subcommand (not fixed position)
@ 2019-09-24  5:51 zsh hh
  0 siblings, 0 replies; only message in thread
From: zsh hh @ 2019-09-24  5:51 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 945 bytes --]

I want to create a completion script for:

> program [OPTS] SUBCOMMAND [SUBCOMMAND-OPTS] [ARGS]

A common approach is:
  _arguments -C \
    '1: :cmds' \
    '*::arg:->args' \
  && ret=0

  case $state in
    (args)
       case $line[1] in
         (subcmd1|subcmd2)
           _message 'no more arguments' && ret=0
         ;;
         (subwithextraopts)
           _arguments ...
             && ret=0
         ;;
         (othersubwithextraopts)
           _arguments ...
             && ret=0
         ;;
 esac

esac

But that relies on subcommand being at $line[1] which is rarely the
case (at least in my application)


git is actually a good example:

git -TAB #tabs git options

git add -TAB #tabs git-add options

git --bare log -TAB #tabs git-log options (but log is not $line[1]

That leads to the idea using git completion as reference, which in
turn leads to the question: how to debug such a completion?

It is a very extensive...

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-24  5:51 how to debug completion or: how to change _arguments depending on subcommand (not fixed position) zsh hh

zsh-users

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-users

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.users


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git