Skip to content

Commit 6601031

Browse files
author
xero harrison
committed
clean up output
now you can pipe the output directly into other applications. `gitio https://github.com/syntax-samurai/gitio -v gitio.sh | xsel -b`
1 parent b13b564 commit 6601031

File tree

1 file changed

+39
-32
lines changed

1 file changed

+39
-32
lines changed

gitio

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,50 +31,57 @@ usage () {
3131
-v shortlink
3232
-h display this screen
3333
EOF
34-
exit 0
34+
exit 0
3535
}
3636

3737
err() {
38-
echo $1
39-
usage
38+
echo $1
39+
usage
4040
}
4141

4242
optstest() {
43-
found=0
44-
for arg in "$@"
45-
do
46-
if echo $arg | cut -d/ -f3 | grep -q "github.com\|raw.githubusercontent.com"
47-
then
48-
GHURL=$arg
49-
found=1
50-
elif [ $arg = "-h" ]
51-
then
52-
usage
53-
elif [ $arg = "-v" ]
54-
then
55-
:
56-
else
57-
VANITY=$arg
58-
fi
59-
done
60-
if [ $found = 0 ]
61-
then
62-
err " must be a valid github.com url!"
63-
fi
43+
found=0
44+
for arg in "$@"
45+
do
46+
if echo $arg | cut -d/ -f3 | grep -q "github.com\|raw.githubusercontent.com"
47+
then
48+
GHURL=$arg
49+
found=1
50+
elif [ $arg = "-h" ]
51+
then
52+
usage
53+
elif [ $arg = "-v" ]
54+
then
55+
:
56+
else
57+
VANITY=$arg
58+
fi
59+
done
60+
if [ $found = 0 ]
61+
then
62+
err " must be a valid github.com url!"
63+
fi
6464
}
6565

6666
case $# in
67-
1)
68-
optstest $1 ;;
69-
3)
70-
optstest $1 $2 $3 ;;
71-
*)
72-
err " invalid number of arguments!" ;;
67+
1)
68+
optstest $1 ;;
69+
3)
70+
optstest $1 $2 $3 ;;
71+
*)
72+
err " invalid number of arguments!" ;;
7373
esac
7474

7575
if [ -z "$VANITY" ]
7676
then
77-
curl -i http://git.io -F "url=$GHURL"
77+
url=`curl -is http://git.io -F "url=$GHURL" | grep -i "location" | cut -d' ' -f2`
7878
else
79-
curl -i http://git.io -F "url=$GHURL" -F "code=$VANITY"
79+
url=`curl -is http://git.io -F "url=$GHURL" -F "code=$VANITY" | grep -i "location" | cut -d' ' -f2`
80+
fi
81+
82+
if [ -z $url ]
83+
then
84+
err " must be a valid github.com url!"
85+
else
86+
echo $url
8087
fi

0 commit comments

Comments
 (0)