1
0
mirror of https://github.com/zplug/zplug synced 2025-08-30 09:40:38 +02:00
zplug/base/support/gh-r.zsh
Naoki Mizuno e01833c95e Change directory structure
lib/     -> base/
src/     -> misc/
src/ext/ -> base/sources/
2016-04-13 01:25:51 -04:00

48 lines
1.1 KiB
Bash

#!/bin/zsh
__import "core/git"
__import "print/print"
__zplug::support::gh-r::get_latest() {
local repo curl
local url_format
repo="${1:?}"
url_format="https://github.com/$repo/releases/latest"
if (( $+commands[curl] )); then
curl="curl -fsSL"
elif (( $+commands[wget] )); then
curl="wget -qO -"
fi
eval "$curl $url_format" 2>/dev/null \
| grep -o '/'"$repo"'/releases/download/[^"]*' \
| awk -F/ '{print $6}' \
| sort \
| uniq
}
__zplug::support::gh-r::get_state() {
local state
local name="${1:?}"
local dir="${2:?}"
local url="https://github.com/$name/releases"
if [[ "$(__zplug::support::gh-r::get_latest "$name")" == "$(cat "$dir/INDEX")" ]]; then
state="up to date"
else
state="local out of date"
fi
case "$state" in
"local out of date")
state="${fg[red]}${state}${reset_color}"
;;
"up to date")
state="${fg[green]}${state}${reset_color}"
;;
esac
__zplug::print::print::put "($state) '${url:-?}'\n"
}