Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Simplest way to choose one of several commands
- X-seq: zsh-users 14347
- From: Nikolai Weibull <now@xxxxxxxx>
- To: Mikael Magnusson <mikachu@xxxxxxxxx>
- Subject: Re: Simplest way to choose one of several commands
- Date: Tue, 8 Sep 2009 00:17:30 +0200
- Cc: Zsh Users <zsh-users@xxxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=gcyYAqpHmnsy37JDe96C4Vf80S8gsVMAbQnoZXhxWMQ=; b=KALije1ASCl429Ur8T7+3gya5k7RjWk6PfRXwanpRZVemrJUOvcdPlUbiweJjT6K4W evoCJDbhbkuAFFYPxo68I6wPD8mTwaNhaEAzYscfcfQSu1newMrUC0kTsglWzbWbiFMG 5D2xv2HOvmzwnZIkmj4TRA/e7WJq7udD8R130=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=LFy0WPNrDEOnfrLhqe+ES+uymVBxbNvv7k4esyRCUYHIwKu1s2abkEmm35GjYBukLZ uZ8hJRXep2rKvf07jJLUKcNOvcj2H7pzQq6QH+yo4Whmx4dtk860fJUbwezuqvwdNABl EvXRRX6uR/9dPIRBXk+nNKRh64uwzl4wfwkf4=
- In-reply-to: <237967ef0909071449w1c7cdadblb615d61bfc90c235@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <dbfc82860909070922u19535071v17842f1f10ffed4@xxxxxxxxxxxxxx> <ed7b1c610909071433u6e154903ye3b13eeef1894f49@xxxxxxxxxxxxxx> <237967ef0909071449w1c7cdadblb615d61bfc90c235@xxxxxxxxxxxxxx>
- Sender: nikolai.weibull@xxxxxxxxx
On Mon, Sep 7, 2009 at 23:49, Mikael Magnusson<mikachu@xxxxxxxxx> wrote:
> 2009/9/7 Baptiste Daroussin <baptiste.daroussin@xxxxxxxxx>:
>> 2009/9/7 Nikolai Weibull <now@xxxxxxxx>:
>>> 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.)
>> all the command in path are in the associative array $commands so
>> assuming that at least ls is in the path :
>> alias ls="${commands[gls]:-$commands[ls]} --color"
>> it seems simpler to me
Ah, thanks. I forgot about $commands. I wish it was something
simpler, but perhaps Iâm asking for too much.
> Some meandering through the man page later:
> % echo ${${:-$commands[(R)*/(ls|cat)]}[1]}
> /bin/ls
> % echo ${${:-$commands[(R)*/(ls|cat)]}[2]}
> /bin/cat
I can one-up you on that:
$commands[(r)*/(g|)ls]
Note, though, that neither mine nor your version chooses gls over ls
if both are installed. This just chooses whatever happens to be
first, and, Iâm guessing, it will be pretty random.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author