zsh-users
 help / color / mirror / code / Atom feed
* Symlinks in recursive glob
@ 2018-11-05  0:17 ` Dominik Ritter
  2018-11-05  9:52   ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Dominik Ritter @ 2018-11-05  0:17 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 680 bytes --]

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.

Both chasedots and chaselinks are turned off.

I've seen solutions to this with either using find or traversing the path
up manually.. Both solutions seem cumbersome to me.

Thanks,
Dominik

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Symlinks in recursive glob
  2018-11-05  0:17 ` Symlinks in recursive glob Dominik Ritter
@ 2018-11-05  9:52   ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2018-11-05  9:52 UTC (permalink / raw)
  To: zsh-users

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-11-05  9:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20181105001937epcas3p2ebd558b47eca5ed019b8762a91e96b96@epcas3p2.samsung.com>
2018-11-05  0:17 ` Symlinks in recursive glob Dominik Ritter
2018-11-05  9:52   ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).