X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=etc%2Fzsh%2Fzshrc;h=7bd4416eaca611b46a63c8d734dbdd430b4b92bd;hb=b0fec259a8d00c3ffcb8f68998a8a9b502fcff13;hp=4e7ef0906066b2a99f67db21052353128b35a5e0;hpb=8564319c233b615c6b2500f166cfdcc0e8d1185c;p=grml-etc-core.git diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 4e7ef09..7bd4416 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -242,7 +242,7 @@ function zrcautoload() { local -i ffound ffile=$1 - (( found = 0 )) + (( ffound = 0 )) for fdir in ${fpath} ; do [[ -e ${fdir}/${ffile} ]] && (( ffound = 1 )) done @@ -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 " 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 @@ -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.