From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28365 invoked by alias); 20 Apr 2011 16:44:46 -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: 15973 Received: (qmail 26249 invoked from network); 20 Apr 2011 16:44:44 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at mail.nih.gov designates 128.231.90.108 as permitted sender) X-IronPortListener: NIH_Relay X-SBRS: None X-IronPort-AV: E=Sophos;i="4.64,247,1301889600"; d="scan'208";a="246932853" X-Authentication-Warning: cosy.cit.nih.gov: arif set sender to Anthony R Fletcher using -f Date: Wed, 20 Apr 2011 12:44:37 -0400 From: Anthony R Fletcher To: Subject: Re: Suffix alias for README files Message-ID: <20110420164437.GA25496@cosy.cit.nih.gov> Mail-Followup-To: zsh-users@zsh.org References: <20110419135909.GA21897@cosy.cit.nih.gov> <1590CA5C-3329-4DF1-8E73-E7FE218A21D9@biskalar.de> <20110420124129.GB18289@cosy.cit.nih.gov> <110420080625.ZM16423@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <110420080625.ZM16423@torch.brasslantern.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.0 (cake.cit.nih.gov [165.112.93.31]); Wed, 20 Apr 2011 12:44:37 -0400 (EDT) On 20 Apr 2011 at 08:06:25, Bart Schaefer wrote: > > I can use suffix aliases to display various .txt files. > > Can I do a similar thing for README files? So the "command" > > > > /some/path/README > > > > will really run the command > > > > less /some/path/README > > Depending on your version of zsh, you can do this either with the > zle-line-finish widget or by replacing the accept-line widget. > > zle-line-finish() { > setopt localoptions extendedglob > if [[ -z "$PREBUFFER" && "$BUFFER" = ([^[:space:]]#/)#README ]] > then BUFFER="less $BUFFER" > fi > } > zle -N zle-line-finish > > Or > > accept-line() { > setopt localoptions extendedglob > if [[ -z "$PREBUFFER" && "$BUFFER" = ([^[:space:]]#/)#README ]] > then BUFFER="less $BUFFER" > fi > zle .accept-line "$@" > } > zle -N accept-line Great, the last works for me everywhere and the first works on my newer machines. Thanks. > Aside to zsh-workers: > > If no external command is found but a function command_not_found_handler > exists the shell executes this function with all command line arguments. > > Perhaps "command found but permission denied" should be treated the same > as "command not found"? Then one could handle this there as well, and > not have to mess with widgets. See also recent discussion of bash/zsh > differences when the command is literally an empty string. Thanks for mentioning "command_not_found_handler". I'd missed that one. Anthony.