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

Re: Finding symbolic links that are outside a tree (comp.unix.shell)



On Jun 7,  5:01pm, Thorsten Kampe wrote:
} Subject: Finding symbolic links that are outside a tree (comp.unix.shell)
}
} So can this be done with zsh globbing? I couldn't get any further as
} "print -l **/*(@)" which prints only symbolic links but doesn't do
} anything for "that are outside a tree".

I'm not entirely sure I understand the question, but I *think* the
answer is to begin with something like

    function follow () {
      stat -A reply +link $REPLY
      if [[ $reply != /* ]]
      then reply=( $PWD/$reply )
      fi
    }

    zmodload -i zsh/stat
    declare -a links
    links=( **/*(@+follow) )
    links=( ${links#$PWD/} )

    integer n=${(@)#${(s:/:)PWD}}

Then walk the $links array and print every entry that begins with a slash
or has more leading ../ than the value of $n.

For older versions of zsh you need

    links=( **/*(@e:follow:) )

instead of the +follow shorthand.



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