aboutsummaryrefslogtreecommitdiff
path: root/sys/code/sys/gitio
blob: b6a79833a59d252573cb75674ce62fcf930cc330 (plain)
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
73
74
75
76
77
78
79
80
#!/bin/sh
#
#          ██   ██      ██
#   █████ ░░   ░██     ░░
#  ██░░░██ ██ ██████    ██  ██████
# ░██  ░██░██░░░██░    ░██ ██░░░░██
# ░░██████░██  ░██     ░██░██   ░██
#  ░░░░░██░██  ░██     ░██░██   ░██
#   █████ ░██  ░░██  ██░██░░██████
#  ░░░░░  ░░    ░░  ░░ ░░  ░░░░░░
#
# create short / vanity github urls
#         ▟▙
# ▟▒░░░░░░░▜▙▜████████████████████████████████▛
# ▜▒░░░░░░░▟▛▟▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▛
#         ▜▛
# xero / syntax-samurai <http://git.io/gitio.sh>

usage () {
    cat <<EOF

         ▟▙
 ▟▒░░░░░░░▜▙▜████████████████████████████████▛
 ▜▒░░░░░░░▟▛▟▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▛
         ▜▛

 create short / vanity github urls
 usage: $(basename $0) http://github.com/something [-v mini]
 
 options:
  -v   shortlink
  -h   display this screen
EOF
	exit 0
}

err() {
	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
}

case $# in
	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"
else
	curl -i http://git.io -F "url=$GHURL" -F "code=$VANITY"
fi