From 307ce5aafafec914f11572b9015843d87fa9381c Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Wed, 31 Aug 2011 21:25:56 +0200 Subject: [PATCH] #23 github: rewrite using arguments (properly sets context and allow extension) --- _github | 70 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/_github b/_github index c0d91fe..a4f74c6 100644 --- a/_github +++ b/_github @@ -20,32 +20,48 @@ # ------------------------------------------------------------------------------ -local -a _1st_arguments -_1st_arguments=( - 'browse:Open this repo in a web browser' - 'clone:Clone a repo' - 'config:Automatically set configuration info, or pass args to specify' - 'create-from-local:Create a new GitHub repository from the current local repository' - 'create:Create a new empty GitHub repository' - 'fetch:Fetch from a remote to a local branch' - 'fetch_all:Fetch all refs from a user' - 'fork:Forks a GitHub repository' - 'home:Open this repos master branch in a web browser' - 'ignore:Ignore a SHA from github network commits' - 'info:Info about this project' - 'issues:Project issues tools' - 'network:Project network tools - sub-commands : web [user], list, fetch, commits' - 'open:Open the given user/project in a web browser' - 'pull-request:Generate the text for a pull request' - 'pull:Pull from a remote' - 'search:Search GitHub for the given repository name' - 'track:Track another users repository' -) +typeset -A opt_args +local context state line curcontext="$curcontext" -_arguments \ - '*:: :->subcmds' && return 0 +_github() { + local ret=1 -if (( CURRENT == 1 )); then - _describe -t commands "github subcommand" _1st_arguments - return -fi + _arguments -C \ + '1:cmd:->cmds' \ + '*::arg:->args' \ + && ret=0 + + case "$state" in + (cmds) + local commands; commands=( + 'admin:open this repo'\''s Admin panel a web browser' + 'browse:open this repo in a web browser' + 'clone:clone a repo' + 'config:automatically set configuration info, or pass args to specify' + 'create:create a new, empty GitHub repository' + 'create-from-local:create a new GitHub repository from the current local repository' + 'fetch:fetch from a remote to a local branch' + 'fetch_all:fetch all refs from a user' + 'fork:forks a GitHub repository' + 'home:open this repo'\''s master branch in a web browser' + 'ignore:ignore a SHA' + 'info:info about this project' + 'issues:project issues tools' + 'network:project network tools' + 'open:open the given user/project in a web browser' + 'pull:pull from a remote' + 'pull-request:generate the text for a pull request' + 'search:search GitHub for the given repository name' + 'track:track another user'\''s repository' + ) + _describe -t commands 'command' commands && ret=0 + ;; + (args) + curcontext="${curcontext%:*:*}:github-cmd-$words[1]:" + ;; + esac + + return ret +} + +_github "$@"