-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitshort.sh
More file actions
executable file
·72 lines (62 loc) · 1.19 KB
/
gitshort.sh
File metadata and controls
executable file
·72 lines (62 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh
usage () {
cat <<EOF
__ __ ____ ___ _ _ __ ___ ____
/ _)( )(_ _)/ __)( )( )/ \( ,)(_ _)
( (/\ )( )( \__ \ )__(( () )) \ )(
\__/(__) (__) (___/(_)(_)\__/(_)\_)(__)
Create short or vanity urls with git.io
usage: $(basename $0) http://github.com/something [-v mini]
options:
-v desired vanity
-h display this screen
EOF
exit 0
}
err() {
echo $1
usage
}
optstest() {
found=0
for arg in "$@"
do
if echo $arg | awk -F '/' '$3 !~ /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 $1 ;;
3)
optstest $1 $2 $3 ;;
*)
err " invalid number of arguments!" ;;
esac
if [ -z "$VANITY" ]
then
url=`curl -is https://git.io -F "url=$GHURL" | awk '/Location:/ { print $2 }'`
else
url=`curl -is https://git.io -F "url=$GHURL" -F "code=$VANITY" | awk '/Location:/ { print $2 }'`
fi
if [ -z $url ]
then
err " must be a valid github.com url!"
else
echo $url
fi