This repository has been archived on 2022-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
prezto/modules/git/functions/_git-hub-browse

45 lines
1.0 KiB
Plaintext
Raw Normal View History

#compdef git-hub-browse
#autoload
2012-01-31 23:37:51 -05:00
#
2012-09-25 01:46:41 -04:00
# Completes git-hub-browse.
2012-01-31 23:37:51 -05:00
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
2012-09-29 13:42:15 -04:00
local state expl remotes remote branches_or_tags branches tags files ret=1
_arguments -C -s -S \
'1::args:->remote' \
2012-09-24 17:57:48 -04:00
'2::args:->branch-or-tag' \
'3::args:->file' && ret=0
case "$state" in
(remote)
2012-09-29 23:17:39 -04:00
remotes=($(git config --get-regexp 'remote.*.url' | cut -d. -f2))
_describe -t branch 'remotes' remotes && ret=0
;;
2012-09-24 17:57:48 -04:00
(branch-or-tag)
remote="$words[(($CURRENT - 1))]"
2012-09-24 17:57:48 -04:00
branches_or_tags=($(
2012-09-29 23:17:39 -04:00
git ls-remote --heads --tags "$remote" 2>/dev/null | cut -f2
))
2012-09-24 17:57:48 -04:00
branches=(HEAD ${${(M)branches_or_tags[@]##refs/heads/?##}##refs/heads/})
tags=(${${(M)branches_or_tags[@]##refs/tags/?##}##refs/tags/})
_describe -t branch 'branches' branches && ret=0
2012-09-24 17:57:48 -04:00
_describe -t tag 'tags' tags && ret=0
;;
(file)
files=(${(0)"$(_call_program files git ls-files -z --exclude-standard 2>/dev/null)"})
_wanted file expl 'file' _multi_parts - / files && ret=0
;;
esac
return $ret