2012-03-30 15:45:37 +00:00
|
|
|
#
|
|
|
|
# Shortens GitHub URLs.
|
|
|
|
#
|
|
|
|
# Authors:
|
2014-02-08 21:51:51 +00:00
|
|
|
# Joel Kuzmarski <leoj3n@gmail.com>
|
2012-03-30 15:45:37 +00:00
|
|
|
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
|
|
|
#
|
|
|
|
|
|
|
|
local url="$1"
|
|
|
|
|
|
|
|
if [[ -z "$url" ]]; then
|
2014-02-08 21:51:51 +00:00
|
|
|
print "usage: $0 [ url | - ] [slug]" >&2
|
|
|
|
return 1
|
|
|
|
elif [[ "$url" == '-' ]]; then
|
|
|
|
read url <&0
|
|
|
|
elif [[ "$url" != *github.com* ]]; then
|
|
|
|
url="https://github.com/$url"
|
2012-03-30 15:45:37 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if (( $+commands[curl] )); then
|
2014-02-08 21:51:51 +00:00
|
|
|
local result="$(curl -s -i 'http://git.io' -F "url=$url" -F "code=$2")"
|
|
|
|
|
|
|
|
if [[ $result == *Unprocessable* ]]; then
|
|
|
|
print "$0: the slug '$2' is already taken!" >&2
|
|
|
|
else
|
|
|
|
print $result | grep 'Location:' | sed 's/Location: //'
|
|
|
|
fi
|
2012-03-30 15:45:37 +00:00
|
|
|
else
|
|
|
|
print "$0: command not found: curl" >&2
|
|
|
|
fi
|
|
|
|
|