From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22320 invoked by alias); 2 Oct 2016 00:26:20 -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: 21997 Received: (qmail 12689 invoked from network); 2 Oct 2016 00:26:20 -0000 X-Qmail-Scanner-Diagnostics: from fw.sigpipe.cz 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(213.192.55.98):SA:0(-3.1/5.0):. Processed in 0.552156 secs); 02 Oct 2016 00:26:20 -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=-3.1 required=5.0 tests=RP_MATCHES_RCVD autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: neuhauser@sigpipe.cz X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at sigpipe.cz does not designate permitted sender hosts) Date: Sun, 2 Oct 2016 02:19:31 +0200 From: Roman Neuhauser To: zsh-users@zsh.org Subject: completion implementation woes Message-ID: <20161002001931.GA686081@isis.sigpipe.cz> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8:iso-8859-2" Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.6.1 (2016-04-27) hello, i have difficult time with completion for a git subcommand i wrote, and would appreciate a little help. the tool has this synopsis (all options have one-letter equivalents, only the long versions are listed here to keep it simpler): git [git-opts] dirs -h | --help git [git-opts] dirs activate REPO git [git-opts] dirs active [--full | --relative | --short] git [git-opts] dirs clone [--no-activate] URL [REPO] git [git-opts] dirs init [--no-activate] REPO git [git-opts] dirs list [--full | --relative | --short] the option handling code requires options in places indicated by the synopsis (`git dirs init stuff --no-activate` is an error). below is my failed attempt at implementing the completion, with descriptions of and questions about its behaviors. the code largely cargo-cults Completion/Unix/_cvs as seen in zsh-5.2, yet it doesn't work beyond _git-dirs-_verb (_arguments -> _describe). _arguments -> _arguments chains behave strangely. i'm apparently missing something about _arguments: _cvs chains _arguments calls in the same way, why doesn't mine work? #compdef git-dirs #description manage multiple git dirs # vim: ts=2 sts=2 sw=2 et fdm=marker cms=\ #\ %s function _git-dirs # {{{ { local -A opt_args local -a state _git-dirs-_args \ - '(help)' \ '-h[display usage]' \ '--help[display man page]' \ - 'command' \ ":command:_git-dirs-_verb" \ "*:option or operand:_git-dirs-_verb-arg" } # }}} function _git-dirs-_verb # {{{ { local -a _commands=( activate:'Associate $PWD with REPO' active:'Show the currently active repository' clone:'Clone URL into .git-dirs/repo.d/REPO' init:'Initialize a repository in .git-dirs/repo.d/REPO' list:'List repositories in .git-dirs/repo.d' ) _describe -t commands command _commands } # }}} function _git-dirs-_verb-arg # {{{ { local cmd=$words[2] local rv=1 :; _call_function rv _git-dirs-$cmd \ || _message -r "unknown command: $cmd" :; return $rv } # }}} function _git-dirs-_args # {{{ { _arguments -S -s : "$@" } # }}} # $ git dirs activate # #### no more arguments #### function _git-dirs-activate # {{{ { local -a repos=(.git-dirs/repo.d/*(/N:t)) _git-dirs-_args \ ":REPO:($repos)" } # }}} # $ git dirs clone # #### REPO #### # why does it expect REPO? what happened to URL? function _git-dirs-clone # {{{ { _git-dirs-_args \ {-N,--no-activate}'[Do not activate the repository]' \ ':URL: ' \ '::REPO: ' } # }}} # $ git dirs init (inserts '-') # #### option #### --no-activate -N -- Do not activate the repository # why does it insert a dash? `git dirs clone ` has # a very similar _arguments call and does something else. # $ git dirs init -N # #### no more arguments #### # why all the s below? what makes them different # from the "no more arguments" cases? ( means no output # from the completion system) # $ git dirs init -N # # $ git dirs init --no-activate (inserts space) # # $ git dirs init --no-activate # function _git-dirs-init # {{{ { _git-dirs-_args \ {-N,--no-activate}'[Do not activate the repository]' \ ':REPO: ' } # }}} # $ git dirs active # function _git-dirs-active _git-dirs-list # {{{ { _git-dirs-_args \ - '(full)' \ {-f,--full}'[Display full paths]' \ - '(relative)' \ {-r,--relative}'[Display relative paths]' \ - '(short)' \ {-s,--short}'[Display basenames]' } # }}} _git-dirs "$@" -- roman