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

Re: Setting paths with ~'s in values.



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