rwxrob-dot/scripts/_old/gh
Rob Muhlestein 2ea0289e9f Rebase
2022-02-09 02:29:05 -05:00

43 lines
982 B
Bash
Executable File

#!/bin/bash
declare subcommand="$1"; shift
declare -r gold=$'\033[38;2;250;130;10m'
declare -r cyan=$'\033[38;2;0;255;255m'
declare -r reset=$'\033[0m'
ziplink () {
if [[ -z "$1" ]]; then
echo "usage: gh ziplink <account>/<repo>"
fi
curl -s "https://api.github.com/repos/$1/releases/latest" |jq -r .zipball_url
}
zipball () {
if [[ -z "$1" ]]; then
echo "usage: gh zipball <account>/<repo>"
fi
declare link=$(ziplink "$1")
declare file=${1##*/}.${link##*/}.zip
echo "${gold}Downloading ${cyan}$link$reset -> ${cyan}$file$reset"
curl -s -L "$link" -o "$file"
}
declare -a commands=(ziplink zipball)
for i in ${commands[@]}; do
if [[ $i == "$subcommand" ]]; then
"$subcommand" $*
exit 0
fi
done
######################### Tab Completion Context ########################
# remember COMP_LINE is changed by shift
if [ -n "$COMP_LINE" ]; then
for cmd in ${commands[@]}; do
[[ "${cmd:0:${#1}}" == "$1" ]] && echo $cmd
done
exit 0
fi