From: "Jérémie Roquet" <arkanosis@gmail.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: Neat hash -d trick
Date: Fri, 22 Oct 2010 10:39:27 +0200 [thread overview]
Message-ID: <AANLkTikkbqERg09pkx95Tji6YZ=WpcGVY4Cu+_j0ivmp@mail.gmail.com> (raw)
In-Reply-To: <AANLkTimewqEvxBaQwqv1Sp=+OOjwmK_cgghM=VVC-Db2@mail.gmail.com>
2010/10/22 Mikael Magnusson <mikachu@gmail.com>:
> # 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
next prev parent reply other threads:[~2010-10-22 8:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-21 22:34 Nikolai Weibull
2010-10-22 4:05 ` Bart Schaefer
2010-10-22 7:28 ` Mikael Magnusson
2010-10-22 8:09 ` Julien Nicoulaud
2010-10-22 8:39 ` Jérémie Roquet [this message]
2010-10-22 10:29 ` Nikolai Weibull
2010-10-22 14:24 ` Oliver Kiddle
2010-10-27 15:45 ` Jean-Rene David
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='AANLkTikkbqERg09pkx95Tji6YZ=WpcGVY4Cu+_j0ivmp@mail.gmail.com' \
--to=arkanosis@gmail.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).