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

Re: Symlinks in recursive glob



On Mon, 2018-11-05 at 01:17 +0100, Dominik Ritter wrote:
> Hi all,
> 
> is there a way to not dereference symlinks in a recursive glob?
> 
> Long story:
> I want to search upwards for a file like
> `print (../)#.shorten_folder_marker(:a:h)`, but that dereferences symlinks.
> If I remove the :a modifier I get a relative path, which I cannot use as
> well. The use case is that I want to truncate the folder to the point where
> the .shorten_folder_marker exists. This may be a symlinked directory.
> e.g. I have /tmp/test/1/2/3 and /tmp is a symlink to /private/tmp.

You can't do this directly because ".." is a hard link within the file
system to point to the physical parent.  As soon as you start looking at
the file system tree that way round, you've lost the symbolic links,
which only work one way.

I'm guessing you're starting from a $PWD which contains symbolic links,
right?  So you're going to need to prune that as a variable until you
find a directory with .shorten_folder_marker.  I don't think there's a
way of doing this without a loop...


local dir=$PWD
while [[ $dir != / && ! -f $dir/.shorten_folder_marker ]]; do
  dir=${dir:h}
done


pws



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