[issue627] grml-etc-core: Rewrite of function zurl().
Frank Terbeck
bts at bts.grml.org
Wed Feb 18 16:36:47 CET 2009
Frank Terbeck <ft at grml.org> added the comment:
Alexander Steinböck <bts at bts.grml.org>:
> From 69e0206b11398ef84ff181d853749873a87c65db Mon Sep 17 00:00:00 2001
> From: =?utf-8?q?Alexander=20Steinb=C3=B6ck?= <z3ttacht at grml.org>
> Date: Wed, 18 Feb 2009 16:01:13 +0100
> Subject: [PATCH 1/2] zshrc: Rewrite of function zurl().
>
> Because of changes in the HTML source code of TinyURL, zurl() wasn't working
> properly anymore. For instance, it's now 'copy(http://tinyurl.com/7efkze)'
> instead of 'value="(http://tinyurl.com/7efkze)'.
Heh, I noticed this, too, a few days back. But I was *way* to lazy to
fix it.
> The function however is now just using zsh in-house means and tries to provide
Actually, almost. There's still wget, which could probably be
replaced; but that's not really a priority...
A check if wget is installed would be better, though.
> some decent output. Including TinyURL's new preview feature.
> <http://tinyurl.com/preview.php>
> ---
> etc/zsh/zshrc | 24 ++++++++++++++++--------
> 1 files changed, 16 insertions(+), 8 deletions(-)
>
> diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc
> index 51141a1..9e2864c 100644
> --- a/etc/zsh/zshrc
> +++ b/etc/zsh/zshrc
> @@ -3924,15 +3924,23 @@ fi
>
> # create small urls via tinyurl.com using wget, grep and sed
s:,.*$::
> zurl() {
> +# Prepend 'http://' to given URL where necessary for later output.
> + [[ ${url} != http(s|)://* ]] && url='http://'${url}
> + local tiny='http://tinyurl.com/create.php?url='
> + local grabber='wget -O- -o/dev/null'
> +# Looking for i.e.`copy('http://tinyurl.com/7efkze')' in TinyURL's html code.
> + local search='copy\(?http://tinyurl.com/[[:alnum:]]##*'
> + local result=${(M)${${${(f)"$(${=grabber} ${tiny}${url})"}[(fr)${search}*]}//[()\';]/}%%http:*}
> +# TinyURL provides the rather new feature preview for more confidence. <http://tinyurl.com/preview.php>
> + local preview='http://preview.'${result#http://}
> +
> + printf '%s\n\n' "${PN} - Shrinking long URLs via webservice TinyURL <http://tinyurl.com>."
> + printf '%s\t%s\n\n' 'Given URL:' ${url}
> + printf '%s\t%s\n\t\t%s\n' 'TinyURL:' ${result} ${preview}
> }
I didn't try to understand what's going on here. But I'll trust you,
that it works.
Nice one, if you can fix the comment as I mentioned and add a check
for external programs (wget) via 'check_com -c ...'.
Regards, Frank
----------
files: 0001-zshrc-Rewrite-of-function-zurl.patch, 0002-zshrc-zurl-Testing-existence-of-given-URL-by-pin.patch
messages: 1908, 1910, 1911
nosy: ft, mika, z3ttacht
priority: feature
status: chatting
title: grml-etc-core: Rewrite of function zurl().
topic: configs, grml-etc-core, zsh
_____________________________________
GRML issue tracker <bts at bts.grml.org>
<http://bts.grml.org/grml/issue627>
_____________________________________
More information about the Bugs-changes
mailing list