zsh-users
 help / color / mirror / code / Atom feed
* Automatically run ls on blank line for faster navigation
@ 2012-03-29 20:55 Mitchell Burdette
  2012-03-29 21:07 ` Mikael Magnusson
  0 siblings, 1 reply; 3+ messages in thread
From: Mitchell Burdette @ 2012-03-29 20:55 UTC (permalink / raw)
  To: zsh-users

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!).

Cheers,
Mitch


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Automatically run ls on blank line for faster navigation
  2012-03-29 20:55 Automatically run ls on blank line for faster navigation Mitchell Burdette
@ 2012-03-29 21:07 ` Mikael Magnusson
  2012-03-29 21:40   ` Mitchell Burdette
  0 siblings, 1 reply; 3+ messages in thread
From: Mikael Magnusson @ 2012-03-29 21:07 UTC (permalink / raw)
  To: Mitchell Burdette; +Cc: zsh-users

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Automatically run ls on blank line for faster navigation
  2012-03-29 21:07 ` Mikael Magnusson
@ 2012-03-29 21:40   ` Mitchell Burdette
  0 siblings, 0 replies; 3+ messages in thread
From: Mitchell Burdette @ 2012-03-29 21:40 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: zsh-users

I like that method more, it's like a hook of sorts. For me I had to
add the line:
> zle -N auto-ls
before the line:
> zle -N accept-line auto-ls
otherwise it would complain that there's no widget 'auto-ls'.

I'm wondering what other cool tricks this could be used for :)

On Thu, Mar 29, 2012 at 4:07 PM, Mikael Magnusson <mikachu@gmail.com> wrote:
> 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-03-29 21:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-29 20:55 Automatically run ls on blank line for faster navigation Mitchell Burdette
2012-03-29 21:07 ` Mikael Magnusson
2012-03-29 21:40   ` Mitchell Burdette

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).