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

Re: [[ -x =command ]]



On Wed, Oct 17, 2007 at 10:40:59AM +1300, Atom Smasher wrote:
> On Tue, 16 Oct 2007, Frank Terbeck wrote:
>
>>> b) if not, what's the correct way to test if a command exists in the 
>>> PATH?
>>
>> [[ -x $(which most) ]] && echo yay || echo nay
> =============
>
> cool, thanks...
>
> [[ -x $(whence -p most) ]] && export PAGER=$(whence -p most)
[...]

zmodload -i zsh/parameters
export PAGER=\
${commands[most]:-\
${commands[less]:-\
${commands[w3m]:-\
${commands[pager]:-\
more}}}}

or, portably:

for PAGER in most less w3m pager more; do
  command -v "$PAGER" > /dev/null 2>&1 && break
done
export PAGER
  
as I don't think you need the full path in $PAGER.

-- 
Stéphane



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