2012-09-29 18:00:38 +00:00
|
|
|
#compdef git-hub-browse
|
2012-01-19 22:32:27 +00:00
|
|
|
#autoload
|
|
|
|
|
2012-02-01 04:37:51 +00:00
|
|
|
#
|
2012-09-25 05:46:41 +00:00
|
|
|
# Completes git-hub-browse.
|
2012-02-01 04:37:51 +00:00
|
|
|
#
|
|
|
|
# Authors:
|
|
|
|
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
|
|
|
#
|
|
|
|
|
2014-07-13 10:36:15 +00:00
|
|
|
if ! is-true "$(command git rev-parse --is-inside-work-tree 2> /dev/null)"; then
|
2012-09-30 19:30:18 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2012-09-29 17:42:15 +00:00
|
|
|
local state expl remotes remote branches_or_tags branches tags files ret=1
|
2012-01-19 22:32:27 +00:00
|
|
|
|
|
|
|
_arguments -C -s -S \
|
|
|
|
'1::args:->remote' \
|
2012-09-24 21:57:48 +00:00
|
|
|
'2::args:->branch-or-tag' \
|
2012-02-02 23:25:21 +00:00
|
|
|
'3::args:->file' && ret=0
|
2012-01-19 22:32:27 +00:00
|
|
|
|
|
|
|
case "$state" in
|
|
|
|
(remote)
|
2014-07-13 10:36:15 +00:00
|
|
|
remotes=($(command git config --get-regexp 'remote.*.url' | cut -d. -f2))
|
2012-09-30 03:17:39 +00:00
|
|
|
|
2012-01-19 22:32:27 +00:00
|
|
|
_describe -t branch 'remotes' remotes && ret=0
|
|
|
|
;;
|
2012-09-24 21:57:48 +00:00
|
|
|
(branch-or-tag)
|
2012-01-19 22:32:27 +00:00
|
|
|
remote="$words[(($CURRENT - 1))]"
|
2012-09-24 21:57:48 +00:00
|
|
|
|
|
|
|
branches_or_tags=($(
|
2014-07-13 10:36:15 +00:00
|
|
|
command git ls-remote --heads --tags "$remote" 2>/dev/null | cut -f2
|
2012-01-19 22:32:27 +00:00
|
|
|
))
|
2012-09-24 21:57:48 +00:00
|
|
|
|
|
|
|
branches=(HEAD ${${(M)branches_or_tags[@]##refs/heads/?##}##refs/heads/})
|
|
|
|
tags=(${${(M)branches_or_tags[@]##refs/tags/?##}##refs/tags/})
|
|
|
|
|
2012-01-19 22:32:27 +00:00
|
|
|
_describe -t branch 'branches' branches && ret=0
|
2012-09-24 21:57:48 +00:00
|
|
|
_describe -t tag 'tags' tags && ret=0
|
2012-01-19 22:32:27 +00:00
|
|
|
;;
|
2012-02-02 23:25:21 +00:00
|
|
|
(file)
|
2014-07-13 10:36:15 +00:00
|
|
|
files=(${(0)"$(_call_program files command git ls-files -z --exclude-standard 2>/dev/null)"})
|
2012-02-02 23:25:21 +00:00
|
|
|
_wanted file expl 'file' _multi_parts - / files && ret=0
|
|
|
|
;;
|
2012-01-19 22:32:27 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
return $ret
|
2012-01-21 00:48:24 +00:00
|
|
|
|