From: Mikael Magnusson <mikachu@gmail.com>
To: Mitchell Burdette <mitchell.burdette@gmail.com>
Cc: zsh-users@zsh.org
Subject: Re: Automatically run ls on blank line for faster navigation
Date: Thu, 29 Mar 2012 23:07:11 +0200 [thread overview]
Message-ID: <CAHYJk3TFBoBc67-gZBWaA34gQ4osr=uxAZVFC14wQ+cug7LCqA@mail.gmail.com> (raw)
In-Reply-To: <CAJt4KPYvi04qd0=0=2_QA6gu9EP56vjnYyhBUpC1S30SHAjXvQ@mail.gmail.com>
On 29 March 2012 22:55, Mitchell Burdette <mitchell.burdette@gmail.com> wrote:
> I rigged up a function that makes navigation super fast in zsh. If you
> hit enter on a blank line, it runs ls automatically.
>
> Just add the following to your .zshrc:
> auto-ls () {
> if [[ $#BUFFER -eq 0 ]]; then
> echo ""
> ls
> zle redisplay
> else
> zle accept-line
> fi
> }
> zle -N auto-ls
> bindkey '^M' auto-ls
>
> To get the ^M correct in vim, hit <Ctrl+V><Enter>. You could really
> make this run whatever you want, on any key you want, but I like this
> shortcut in particular (It goes great with autocd!).
A (slightly) more generic way to do it would be
auto-ls () {
if [[ $#BUFFER -eq 0 ]]; then
echo ""
ls
zle redisplay
else
zle .$WIDGET
fi
}
zle -N accept-line auto-ls
zle -N other-widget auto-ls
This uses the same function to wrap any widget, ie you might want it
on accept-and-hold and accept-line-and-down-history as well, or
something. Maybe not. Note that the . in .$WIDGET is important, or it
will call the wrapper recursively, .foo always calls the builtin
widget ignoring any custom widgets by the same name. (And $WIDGET is
obviously the name of the widget that caused the function to be
called).
--
Mikael Magnusson
next prev parent reply other threads:[~2012-03-29 21:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-29 20:55 Mitchell Burdette
2012-03-29 21:07 ` Mikael Magnusson [this message]
2012-03-29 21:40 ` Mitchell Burdette
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='CAHYJk3TFBoBc67-gZBWaA34gQ4osr=uxAZVFC14wQ+cug7LCqA@mail.gmail.com' \
--to=mikachu@gmail.com \
--cc=mitchell.burdette@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).