From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7241 invoked by alias); 29 Mar 2012 21:40:33 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 16935 Received: (qmail 17174 invoked from network); 29 Mar 2012 21:40:30 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,RCVD_IN_DNSWL_LOW, T_DKIM_INVALID autolearn=no version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.214.171 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=zyCwmJZpOe6zKzhikIUObDisWhFb3IK5QZDiM0RcX5Y=; b=guHvZyCPwgVTDCThKtDkP8NFY/DNsXdsj61Y6HNLVDd9MwxjjqNv3pssTHo6oT28mv PfU35VPVgl0hJSRAvCbFrqjp9OZPalSPn5HCT46YcjnoSjWNcfmO4XdodeWJrREPb1d1 BPrJW08XyckV12uMX8tdeqVSS2s9McZATG1dww3EMJVArJhRufCPjCXKAyZOzVF55ghG qpGxsZIF9i3SIYT01gkNRrUfkyzvbLSRCTS6hdB/oEarak/MaC10WESUt1wzsxer7ypd XRfRJWWldtXagNk3Sk8Kml/o7/Hi8cb4rCW2huDPNopm7++3MWbAeGgqsC8uQ714Ka0h cL/Q== MIME-Version: 1.0 In-Reply-To: References: Date: Thu, 29 Mar 2012 16:40:24 -0500 Message-ID: Subject: Re: Automatically run ls on blank line for faster navigation From: Mitchell Burdette To: Mikael Magnusson Cc: zsh-users@zsh.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 wrote= : > On 29 March 2012 22:55, Mitchell Burdette w= rote: >> 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 () { >> =A0 =A0if [[ $#BUFFER -eq 0 ]]; then >> =A0 =A0 =A0 =A0echo "" >> =A0 =A0 =A0 =A0ls >> =A0 =A0 =A0 =A0zle redisplay >> =A0 =A0else >> =A0 =A0 =A0 =A0zle accept-line >> =A0 =A0fi >> } >> zle -N auto-ls >> bindkey '^M' auto-ls >> >> To get the ^M correct in vim, hit . 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 () { > =A0 if [[ $#BUFFER -eq 0 ]]; then > =A0 =A0 =A0 echo "" > =A0 =A0 =A0 ls > =A0 =A0 =A0 zle redisplay > =A0 else > =A0 =A0 =A0 zle .$WIDGET > =A0 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