X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=etc%2Fzsh%2Fzshrc;h=fde07a30e4d7475b2d0b370cbcd57548d12e3dd6;hb=ccc94f4a8dcf92bdf3adacbdbf97c18b55fa0f8d;hp=51141a18ec23ac5369076b60230f5e8ee0733351;hpb=b93d674c5bc4e4327f1ab2ddd3674056d0e8f7f5;p=grml-etc-core.git diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 51141a1..fde07a3 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -1975,7 +1975,7 @@ is4 && [[ $NOPRECMD -eq 0 ]] && precmd () { # adjust title of xterm # see http://www.faqs.org/docs/Linux-mini/Xterm-Title.html case $TERM in - (xterm*|rxvt) + (xterm*|rxvt*) print -Pn "\e]0;%n@%m: %~\a" ;; esac @@ -3922,17 +3922,30 @@ if check_com -c highlight ; then compdef _hl_complete hl fi -# create small urls via tinyurl.com using wget, grep and sed -zurl() { - [[ -z ${1} ]] && print "please give an url to shrink." && return 1 - local url=${1} - local tiny="http://tinyurl.com/create.php?url=" - #print "${tiny}${url}" ; return - wget -O- \ - -o/dev/null \ - "${tiny}${url}" \ - | grep -Eio 'value="(http://tinyurl.com/.*)"' \ - | sed 's/value=//;s/"//g' +# Create small urls via http://tinyurl.com using wget(1). +function zurl() { + [[ -z ${1} ]] && { print "USAGE: zurl " ; return 1 } + + local PN url tiny grabber search result preview + PN=${0} + url=${1} +# Prepend 'http://' to given URL where necessary for later output. + [[ ${url} != http(s|)://* ]] && url='http://'${url} + tiny='http://tinyurl.com/create.php?url=' + if check_com -c wget ; then + grabber='wget -O- -o/dev/null' + else + print "wget is not available, but mandatory for ${PN}. Aborting." + fi +# Looking for i.e.`copy('http://tinyurl.com/7efkze')' in TinyURL's HTML code. + search='copy\(?http://tinyurl.com/[[:alnum:]]##*' + result=${(M)${${${(f)"$(${=grabber} ${tiny}${url})"}[(fr)${search}*]}//[()\';]/}%%http:*} +# TinyURL provides the rather new feature preview for more confidence. + preview='http://preview.'${result#http://} + + printf '%s\n\n' "${PN} - Shrinking long URLs via webservice TinyURL ." + printf '%s\t%s\n\n' 'Given URL:' ${url} + printf '%s\t%s\n\t\t%s\n' 'TinyURL:' ${result} ${preview} } #f2# Print a specific line of file(s).