diff options
Diffstat (limited to '')
-rwxr-xr-x | bin/bin/gitio | 71 |
1 files changed, 39 insertions, 32 deletions
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 |