Skip to content

Commit

Permalink
zshrc: Remove zurl's dependency on =~ type regexp conditions
Browse files Browse the repository at this point in the history
This should improve backwards compatibility with older zsh-versions.

Reported-by: Ilya Novoselov
Signed-off-by: Frank Terbeck <ft@grml.org>
  • Loading branch information
ft committed Nov 9, 2012
1 parent 57bbea3 commit b0fec25
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions etc/zsh/zshrc
Expand Up @@ -2632,12 +2632,15 @@ xtrename() {
# API reference: https://code.google.com/apis/urlshortener/
function zurl() {
emulate -L zsh
setopt extended_glob

if [[ -z $1 ]]; then
print "USAGE: zurl <URL>"
return 1
fi

local PN url prog api json data
local PN url prog api json contenttype item
local -a data
PN=$0
url=$1

Expand All @@ -2655,11 +2658,19 @@ function zurl() {
api='https://www.googleapis.com/urlshortener/v1/url'
contenttype="Content-Type: application/json"
json="{\"longUrl\": \"${url}\"}"
data=$($prog --silent -H ${contenttype} -d ${json} $api)
# Match against a regex and print it
if [[ $data =~ '"id": "(http://goo.gl/[[:alnum:]]+)"' ]]; then
print $match;
fi
data=(${(f)"$($prog --silent -H ${contenttype} -d ${json} $api)"})
# Parse the response
for item in "${data[@]}"; do
case "$item" in
' '#'"id":'*)
item=${item#*: \"}
item=${item%\",*}
printf '%s\n' "$item"
return 0
;;
esac
done
return 1
}

#f2# Find history events by search pattern and list them by date.
Expand Down

0 comments on commit b0fec25

Please sign in to comment.