Skip to content

Commit

Permalink
clean up output
Browse files Browse the repository at this point in the history
now you can pipe the output directly into other applications. 
`gitio https://github.com/syntax-samurai/gitio -v gitio.sh | xsel -b`
  • Loading branch information
xero harrison committed Sep 25, 2015
1 parent b13b564 commit 6601031
Showing 1 changed file with 39 additions and 32 deletions.
71 changes: 39 additions & 32 deletions gitio
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6601031

Please sign in to comment.