bin/bin/gitio #!/bin/sh # # ██ ██ ██ # █████ ░░ ░██ ░░ # ██░░░██ ██ ██████ ██ ██████ # ░██ ░██░██░░░██░ ░██ ██░░░░██ # ░░██████░██ ░██ ░██░██ ░██ # ░░░░░██░██ ░██ ░██░██ ░██ # █████ ░██ ░░██ ██░██░░██████ # ░░░░░ ░░ ░░ ░░ ░░ ░░░░░░ # # create short / vanity github urls # ▟▙ # ▟▒░░░░░░░▜▙▜████████████████████████████████▛ # ▜▒░░░░░░░▟▛▟▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▛ # ▜▛ # xero / syntax-samurai <http://git.io/gitio.sh> usage () { cat <<EOF ▟▙ ▟▒░░░░░░░▜▙▜████████████████████████████████▛ ▜▒░░░░░░░▟▛▟▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▛ ▜▛ create short / vanity github urls usage: $(basename {{&blob}}) http://github.com/something [-v mini] options: -v shortlink -h display this screen EOF exit 0 } err() { echo usage } optstest() { found=0 for arg in "$@" do if echo $arg | awk -F '/' ' !~ /github.com|github.io|githubusercontent.com/ { exit 1 }' then GHURL=$arg found=1 elif [ $arg = "-h" ] then usage elif [ $arg = "-v" ] then : else VANITY=$arg fi done if [ $found = 0 ] then err " must be a valid github.com url!" fi } case $# in 1) optstest ;; 3) optstest ;; *) err " invalid number of arguments!" ;; esac if [ -z "$VANITY" ] then url=`curl -is https://git.io -F "url=$GHURL" | awk '/Location:/ { print }'` else url=`curl -is https://git.io -F "url=$GHURL" -F "code=$VANITY" | awk '/Location:/ { print }'` fi if [ -z $url ] then err " must be a valid github.com url!" else echo $url fi