Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Neat hash -d trick



2010/10/22 Mikael Magnusson <mikachu@xxxxxxxxx>:
> # just type '...' to get '../..'
> rationalise-dot() {
> local MATCH
> if [[ $LBUFFER =~ '(^|/| | Â Â Â|'$'\n''|\||;|&)\.\.$' ]]; then
> ÂLBUFFER+=/
> Âzle self-insert
> Âzle self-insert
> else
> Âzle self-insert
> fi
> }
> zle -N rationalise-dot
> bindkey . rationalise-dot
> # without this, typing a . aborts incremental history search
> bindkey -M isearch . self-insert
>
> You only need the last line to avoid the problem of course.

I'm using something similar, though I'll probably use your test now
because the expansion isn't always appropriate :)

function magic-dot()
{
    if [[ $LBUFFER = *. ]]; then
        LBUFFER+=./
        display-path $LBUFFER
    elif [[ $LBUFFER = *../ ]]; then
        LBUFFER+=../
        display-path $LBUFFER
    else
        zle self-insert
    fi
}
zle -N magic-dot

.. gives ../ so you can use completion without typing the /
... gives ../../
and so on

display-path() prints the target path under the current line, so that
I know where I'm going.
It's a simple trick using xterm control sequences; I don't guarantee
it'll work everywhere but at least it works everywhere I've tested it.

function display-path()
{
    local newpath

    newpath=`pwd`/`echo $1 | sed 's_\(.* \)\?\([^ ]\+\)$_\2_'`
    echo -n "\e7\n\e[40m$newpath:A\e[0m\e[0K\e8\e[B\e[A"
}

The only problem I've with these tricks is when pasting paths with
dots in my shell, because ../../foo/bar becomes ../../../foo/bar

Best regards,

-- 
JÃrÃmie



Messages sorted by: Reverse Date, Date, Thread, Author