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 14346
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxxxxx>
- Subject: Re: Simplest way to choose one of several commands
- Date: Mon, 7 Sep 2009 23:49:46 +0200
- 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:content-type :content-transfer-encoding; bh=n941+xCtqcRUKmbBQR7G9i3DqKIzi8IRq0z6dKeDiG8=; b=Wgskp2jC2Doo1azm0Wf6pxJi7UxouViTCjkD8SWp8AEaE5pIXl2AGDkPKZ1ThIILuq s/MFyAfJaPCUTO9JoNC/HBBHL/JUrFXM097pu95lqFtIaWZFKSDQylq0Cdkw3uCBEap1 pllVPktI99Bq9+coGlT4YjlGbFAv/EI9WaR0s=
- 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 :content-type:content-transfer-encoding; b=hq4c1oEf2S+Bpxjumvi7SvY/eoKt5VQCXJjReiAbFs2Io/t1hAE0Fy8XLMbScY5tyG +6wmtmp14KpoAqHlpEWEhbDm1F4y18GeCC036xQdq51zHIOGhDy/4oqqEYdnBOVcCiEE eoCzC0jB/fwUq50urFKlgZFshTo7zV2IZgYgc=
- In-reply-to: <ed7b1c610909071433u6e154903ye3b13eeef1894f49@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <dbfc82860909070922u19535071v17842f1f10ffed4@xxxxxxxxxxxxxx> <ed7b1c610909071433u6e154903ye3b13eeef1894f49@xxxxxxxxxxxxxx>
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
Some meandering through the man page later:
% echo ${${:-$commands[(R)*/(ls|cat)]}[1]}
/bin/ls
% echo ${${:-$commands[(R)*/(ls|cat)]}[2]}
/bin/cat
Side note, I would have expected $commands[(K)(ls|cat)] to list
/bin/ls and /bin/cat, but it doesn't (it's empty). $commands[(K)ls]
does give /bin/ls though.
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author