Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Suffix alias for README files
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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author