Source original upstream zshrc instead of copying it
[abe:zshrc.git] / zsh.d / 05-grml
1 # Reads original zshrc and contains old zshrc stuff
2
3 source ${HOME}/.zsh/grml-etc-core/etc/zsh/zshrc
4
5 # just type 'cd ...' to get 'cd ../..'
6 rationalise-dot() {
7     if [[ $LBUFFER == *.. ]] ; then
8         LBUFFER+=/..
9     else
10         LBUFFER+=.
11     fi
12 }
13 zle -N rationalise-dot
14 bindkey . rationalise-dot
15
16 bindkey '\eq' push-line-or-edit
17
18 zstyle ':completion:*:*:cd:*:directory-stack' menu yes select
19
20 #f1# Reload zsh setup
21 reload() {
22     if [[ "$#*" -eq 0 ]] ; then
23         [[ -r ~/.zshrc ]] && . ~/.zshrc
24     else
25         local fn
26         for fn in "$@"; do
27             unfunction $fn
28             autoload -U $fn
29         done
30     fi
31 }
32 compdef _functions reload
33
34 function zurl() {
35     [[ -z $1 ]] && { print "USAGE: zurl <URL>" ; return 1 }
36
37     local PN url tiny grabber search result preview
38     PN=${0}
39     url=$1
40 #   Check existence of given URL with the help of ping(1).
41 #   N.B. ping(1) only works without an eventual given protocol.
42     ping -c 1 ${${url#(ftp|http)://}%%/*} >& /dev/null || \
43         read -q "?Given host ${${url#http://*/}%/*} is not reachable by pinging. Proceed anyway? [y|n] "
44
45     if (( $? == 0 )) ; then
46 #           Prepend 'http://' to given URL where necessary for later output.
47             [[ ${url} != http(s|)://* ]] && url='http://'${url}
48             tiny='http://tinyurl.com/create.php?url='
49             if check_com -c wget ; then
50                 grabber='wget -O- -o/dev/null'
51             else
52                 print "wget is not available, but mandatory for ${PN}. Aborting."
53             fi
54 #           Looking for i.e.`copy('http://tinyurl.com/7efkze')' in TinyURL's HTML code.
55             search='copy\(?http://tinyurl.com/[[:alnum:]]##*'
56             result=${(M)${${${(f)"$(${=grabber} ${tiny}${url})"}[(fr)${search}*]}//[()\';]/}%%http:*}
57 #           TinyURL provides the rather new feature preview for more confidence. <http://tinyurl.com/preview.php>
58             preview='http://preview.'${result#http://}
59
60             printf '%s\n\n' "${PN} - Shrinking long URLs via webservice TinyURL <http://tinyurl.com>."
61             printf '%s\t%s\n\n' 'Given URL:' ${url}
62             printf '%s\t%s\n\t\t%s\n' 'TinyURL:' ${result} ${preview}
63     else
64         return 1
65     fi
66 }
67
68 ## END OF FILE #################################################################
69 # Local variables:
70 # mode: sh
71 # End: