From a3d3bdcf454ed84b028038cf98ed40d3e3b29e1e Mon Sep 17 00:00:00 2001 From: xero Date: Sun, 1 Nov 2015 15:44:13 -0500 Subject: update gitio --- bin/bin/gitio | 71 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 32 deletions(-) (limited to 'bin') diff --git a/bin/bin/gitio b/bin/bin/gitio index b6a7983..293ac4f 100755 --- a/bin/bin/gitio +++ b/bin/bin/gitio @@ -31,50 +31,57 @@ usage () { -v shortlink -h display this screen EOF - exit 0 + exit 0 } err() { - echo $1 - usage + echo $1 + usage } optstest() { - found=0 - for arg in "$@" - do - if echo $arg | cut -d/ -f3 | grep -q "github.com\|raw.githubusercontent.com" - 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 + found=0 + for arg in "$@" + do + if echo $arg | cut -d/ -f3 | grep -q "github.com\|raw.githubusercontent.com" + 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 $1 ;; - 3) - optstest $1 $2 $3 ;; - *) - err " invalid number of arguments!" ;; + 1) + optstest $1 ;; + 3) + optstest $1 $2 $3 ;; + *) + err " invalid number of arguments!" ;; esac if [ -z "$VANITY" ] then - curl -i http://git.io -F "url=$GHURL" + url=`curl -is http://git.io -F "url=$GHURL" | grep -i "location" | cut -d' ' -f2` else - curl -i http://git.io -F "url=$GHURL" -F "code=$VANITY" + url=`curl -is http://git.io -F "url=$GHURL" -F "code=$VANITY" | grep -i "location" | cut -d' ' -f2` +fi + +if [ -z $url ] +then + err " must be a valid github.com url!" +else + echo $url fi -- cgit v1.2.1