1
0
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
prezto/modules/git/functions/git-hub-shorten-url

32 lines
667 B

#
# Shortens GitHub URLs.
#
# Authors:
# Joel Kuzmarski <leoj3n@gmail.com>
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
local url="$1"
if [[ -z "$url" ]]; then
print "usage: $0 [ url | - ] [slug]" >&2
return 1
elif [[ "$url" == '-' ]]; then
read url <&0
elif [[ "$url" != *github.com* ]]; then
url="https://github.com/$url"
fi
if (( $+commands[curl] )); then
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
else
print "$0: command not found: curl" >&2
fi