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

Re: Simplest way to choose one of several commands




On 07.09.2009, at 18:22, Nikolai Weibull wrote:

Is there a simpler way of doing the following?

alias ls=${${(f)"$(whence -p {g,}ls)"}[1]}' --color'

I need to select gls, if that’s what’s installed, otherwise ls.  (The
code above assumes that at least ls is installed, which isn’t a
problem.)

Since you’re asking for the simplest way I have to come up with this:

for ls in gls ls; do whence $ls >/dev/null && {alias ls="$ls -- color"; break}; done; unset ls

not so cool, but it works and is parseable by humans :)

Besides this it can be easily extended to adopt handling of different platforms (ls --color on darwin won’t work). I think this kind of thing needs to be done with less zshisms to be powerful.


Sebastian


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