aboutsummaryrefslogtreecommitdiff
path: root/bin/bin/gitio
blob: 0d0f4c60feda219a480abdcb58dda9d063140e66 (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
81
82
83
84
85
86
87
#!/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\|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
  url=`curl -is https://git.io -F "url=$GHURL" | grep -i "location" | cut -d' ' -f2`
else
  url=`curl -is https://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