Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Setting paths with ~'s in values.
- X-seq: zsh-users 2174
- From: Danny Dulai <nirva@xxxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: Setting paths with ~'s in values.
- Date: Mon, 22 Feb 1999 17:20:07 -0500
- Cc: zsh-users@xxxxxxxxxxxxxx
- In-reply-to: <990212140558.ZM11520@xxxxxxxxxxxxxxxxxxxxxxx>; from Bart Schaefer on Fri, Feb 12, 1999 at 02:05:58PM -0800
- Mailing-list: contact zsh-users-help@xxxxxxxxxxxxxx; run by ezmlm
- References: <199902122018.PAA29284@xxxxxxxxxxxxxxxxxx> <990212140558.ZM11520@xxxxxxxxxxxxxxxxxxxxxxx>
Quoting Bart Schaefer (schaefer@xxxxxxxxxxxxxxxx):
> A direct translation would thus be:
>
> for t_path in $(<${HOME}/.zpaths)
> do
> if
> [[ -d $t_path ]]
> then
> eval path=\( $path $t_path \)
> fi
> done
This didnt seem to add the paths with ~ in them because the ~ didnt get
expanded in the test for existence. i had to do an eval before the if, so
the -d would work:
for t_path in $(<${HOME}/.zpaths)
do
eval t_path=$t_path
if [ -d $t_path ]; then
path=( $path $t_path )
fi
done
This works perfectly for me.
> and you don't need the extra step of removing the leading colon. But
> there's a better, faster, smarter way to do the same thing:
>
> eval path=\( ${^$(<${HOME}/.zpaths)}'(|)(/)' \)
>
> Here, the ${^...} takes the place of the "for" loop, the (/) tests a
> glob pattern to see if it refers to a directory, and the (|) turns each
> of the lines from .zpaths into an equivalent glob pattern so that (/)
> test is applied. The quotes and backslashes just make sure that the
> globbing and array assignment steps are delayed until the "eval" runs.
Aftertmuch of fiddling with this, I found it works if I have NULL_GLOB set.
eval path=\( ${^$(<${HOME}/.zpaths)}'(|)(/N)' \)
works even if you don't have that option st (good for using it in .zshenv
if you set optoin in .zshrc).
--
___________________________________________________________________________
Danny Dulai Feet. Pumice. Lotion.
http://www.ishiboo.com/~nirva/ nirva@xxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author