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