-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#compdef ghq | ||
|
||
function _ghq () { | ||
local context curcontext=$curcontext state line | ||
declare -A opt_args | ||
local ret=1 | ||
|
||
_arguments -C \ | ||
'(-h --help)'{-h,--help}'[show help]' \ | ||
'(-v --version)'{-v,--version}'[print the version]' \ | ||
'1: :__ghq_commands' \ | ||
'*:: :->args' \ | ||
&& ret=0 | ||
|
||
case $state in | ||
(args) | ||
case $words[1] in | ||
(get) | ||
_arguments -C \ | ||
'(-u --update)'{-u,--update}'[Update local repository if cloned already]' \ | ||
'-p[Clone with SSH]' \ | ||
'--shallow[Do a shallow clone]' \ | ||
'(-l --look)'{-l,--look}'[Look after get]' \ | ||
'--vcs[Specify vcs backend for cloning]' \ | ||
'(-s --silent)'{-s,--silent}'[Clone or update silently]' \ | ||
'--no-recursive[Prevent recursive fetching]' \ | ||
'--bare[Do a bare clone]' \ | ||
'(-b --branch)'{-b,--branch}'[Specify branch name]' \ | ||
'(-P --parallel)'{-P,--parallel}'[Import parallelly]' \ | ||
'(-)*:: :->null_state' \ | ||
&& ret=0 | ||
;; | ||
(list) | ||
_arguments -C \ | ||
'(-e --exact)'{-e,--exact}'[Perform an exact match]' \ | ||
'--vcs[Specify vcs backend for matching]' \ | ||
'(-p --full-path)'{-p,--full-path}'[Print full paths]' \ | ||
'--unique[Print unique subpaths]' \ | ||
'(-)*:: :->null_state' \ | ||
&& ret=0 | ||
;; | ||
(root) | ||
_arguments -C \ | ||
'--all[Show all roots]' \ | ||
'(-)*:: :->null_state' \ | ||
&& ret=0 | ||
;; | ||
(create) | ||
_arguments -C \ | ||
'--vcs[Specify vcs backend explicitly]' \ | ||
'(-)*:: :->null_state' \ | ||
&& ret=0 | ||
;; | ||
(rm) | ||
_arguments -C \ | ||
'--dry-run[Do not remove actually]' \ | ||
'(-)*:: :->null_state' \ | ||
&& ret=0 | ||
;; | ||
(help|h) | ||
__ghq_commands && ret=0 | ||
;; | ||
esac | ||
;; | ||
esac | ||
|
||
return ret | ||
} | ||
|
||
__ghq_repositories () { | ||
local -a _repos | ||
_repos=( ${(@f)"$(_call_program repositories ghq list --unique)"} ) | ||
_describe -t repositories Repositories _repos | ||
} | ||
|
||
__ghq_commands () { | ||
local -a _c | ||
_c=( | ||
'get:Clone/sync with a remote repository' | ||
'list:List local repositories' | ||
'create:Create a new repository' | ||
"root:Show repositories' root" | ||
'help:Show a list of commands or help for one command' | ||
) | ||
|
||
_describe -t commands Commands _c | ||
} | ||
|
||
_ghq "$@" |