Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Rewrite of zsh-newuser-install (Mikael's subthread)



Marlon wrote on Wed, Apr 07, 2021 at 17:28:29 +0300:
> On 5. Apr 2021, at 22.44, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> > On 4/5/21, Marlon Richert <marlon.richert@xxxxxxxxx> wrote:
> >> # Use suffix aliases to associate file extensions with commands.
> >> # This way, you can open a file simply by typing its name.
> >> # See http://zsh.sourceforge.net/Doc/Release/Shell-Builtin-Commands.html#index-alias
> >> READNULLCMD='less'      # Makes `< foo` do `less < foo`.
> >> alias -s txt='<' md='<' # .txt and .md files
> >> alias -s log='tail -f'  # .log files
> > 
> > Letting the user type < for less is one thing, but you don't really
> > save anything by using a shorter command in the rhs of an alias... it
> > does doesn't allow the user to type more than one filename. eg:
> > % < file1 file2
> > zsh: command not found: file2
> > % less file1 file2
> > file1 (file 1 of 2) lines ?-?/? (END) - Next: file2
> 
> There’s no harm in it, though, is there?

Use of identifiers that consist of punctuation only makes the code more
difficult to read / understand / look up.  For instance, given the
documentation of «alias -s», a new user might look up a «<» command in
the index.

> Plus it makes it so you Don’t Repeat Yourself. Now you have only
> variable you need to change when you want to move from `less` to, say,
> `bat`.

There's a clearer way to do that:

    alias -s txt='$READNULLCMD'

or, to mimic the built-in semantics of $READNULLCMD falling back to $NULLCMD:

    alias -s txt='${READNULLCMD:-${NULLCMD}}'





Messages sorted by: Reverse Date, Date, Thread, Author