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 14348
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Nikolai Weibull <now@xxxxxxxx>
- Subject: Re: Simplest way to choose one of several commands
- Date: Tue, 8 Sep 2009 00:19:45 +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:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=AYu6Kd/o5czU8jj174BzPNi2zo8z10PRkoqYNhBQCFY=; b=UBg80+Dsh+/xVZ1bxTDVskF8gPfrHOUL3fjxYFuBtOSdLrgmuKXbmxsCPxIuIysjEN Hg43xO08g7SxubL4jBRpH1HmvNcjqwMPzK4gLsxVVScGGZTkVLofZ3cu+glYCcxukg+q 6NlFqKk9DioNlUQMin7Uv01ocp+2U9OE/57A8=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=ZNLDu1H0GK8dxASjeKG+gL5D6wajfQz3CExTxHOM4WpASX3dqdemyRpcurLIGCRl6o E/UVS+LLmiyjaxLtLuYmneQlP3lTxCFrPUUm2Ly1ka6WsmcWY6FVZwKc279877IkpvUc gxGpOACEiLeTxJPuxztZUxPJO8Zhx9eWmuA+g=
- In-reply-to: <dbfc82860909071517m1f36e317n4cf1c8645bb179d3@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <dbfc82860909070922u19535071v17842f1f10ffed4@xxxxxxxxxxxxxx> <ed7b1c610909071433u6e154903ye3b13eeef1894f49@xxxxxxxxxxxxxx> <237967ef0909071449w1c7cdadblb615d61bfc90c235@xxxxxxxxxxxxxx> <dbfc82860909071517m1f36e317n4cf1c8645bb179d3@xxxxxxxxxxxxxx>
2009/9/8 Nikolai Weibull <now@xxxxxxxx>:
> 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.
Oops, in all the excitement I forgot about the actual goal of the exercise.
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author