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