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

Re: Adding builtin command option aliases



Ross Goldberg wrote on Wed, 25 Mar 2020 15:21 -0400:
> Would you be willing to add option aliases to builtin commands to align
> with other shells, like bash, so that scripts will be more easily portable
> across multiple shells?

Implementing this doesn't require any changes to zsh itself.  There's
nothing stopping you from writing a «read() { … }» function that wraps
zsh's builtin «read» and supports bash's native options _instead of_
zsh's options (even where option letters have different, incompatible
meanings between the two shells).  You could even package that function
and others like it as a "zsh for bash speakers" shim library, enabled by
a one-line idiom such as «[[ -z $ZSH_VERSION ]] || autoload -U bash-shim».

The "modernish" library might be useful too.

> e.g., bash read has the -a argument, while zsh read has -A.  They seem to
> do the exact same thing.  It's a shame that a script needs to detect which
> shell is running to determine which option to use.

Are you thinking of scripts or of plugins?

Scripts should target either bash or zsh but not both, just like scripts
target either Perl or Python but not both.  Nobody writes programs that
can execute under either Perl or Python depending on what their users
have installed; same for bash and zsh.

On the other hand, for plugins (= code that runs in interactive shells)
it can make sense to try to support both bash and zsh in order to
benefit from economies of scale.

> Providing such interoperability might increase the number of zsh users, and
> ease the transition for macOS 10.15+ & other users

macOS 10.15 users who are used to bash should just install bash and
change their scripts' #! lines appropriately.

Cheers,

Daniel



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