Switched to Zgen Plugin manager

This commit is contained in:
Marty Oehme 2019-02-04 03:32:45 +01:00
parent aee04848cf
commit 9a1cc66bd5
8 changed files with 495 additions and 122 deletions

25
.zshrc.d/003-zurl Normal file
View file

@ -0,0 +1,25 @@
# Create short urls via http://goo.gl using curl(1).
# Contributed back to grml zshrc
# API reference: https://code.google.com/apis/urlshortener/
function zurl {
if [[ -z $1 ]]; then
print "USAGE: $0 <URL>"
return 1
fi
local url=$1
local api='https://www.googleapis.com/urlshortener/v1/url'
local data
# Prepend "http://" to given URL where necessary for later output.
if [[ $url != http(s|)://* ]]; then
url="http://$url"
fi
local json="{\"longUrl\": \"$url\"}"
data=$(curl --silent -H "Content-Type: application/json" -d $json $api)
# Match against a regex and print it
if [[ $data =~ '"id": "(http://goo.gl/[[:alnum:]]+)"' ]]; then
print $match
fi
}