Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Converting absolut symlinks to relative ones...?
- X-seq: zsh-users 21366
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Converting absolut symlinks to relative ones...?
- Date: Sun, 6 Mar 2016 11:38:30 -0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=NuX9DpPLihSuq87e+qa0Jx1j6bPM9RJAZVgZEJnAPYg=; b=z2ApPfX/9ErkzS+RS2z0o4MYHdtcrbeepSCDkqNbPCjbfqCUjZ4RxXbKshKeoR4H1N KE5gPWUKMfB+FjmTN/WsDvSGQ6VfdSYrueqo9+eK6lwZUEYVpCyW9MohrL9aUTvWABUd ZjNhsoutGMMe0aAg2s7DUPoStLWiSvh5GDnzo9GZXmbmqOq5nWy3wCWQ/H+umGH9/vsV R34jf9U+HetrluRm/HMoiHwLM3FJTROipvzEJnRGpinFTk97FaTGdDzt67iBsJIiMvUO A3LVc29NslkYeK6MOnixOT2TjTpaDQm4wp7H+r7Y5R50ZMNKAvtKd3VLwUBSPmhLW6R0 cOWw==
- In-reply-to: <20160306173915.GC10755@lorien.comfychair.org>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20160306132013.GA4938@solfire> <20160306173915.GC10755@lorien.comfychair.org>
On Mar 6, 9:39am, Danek Duvall wrote:
}
} GNU ln has a -r option which does this.
That must be a very recent addition, there's no sign of it in coreutils
8.13 from 2011 (on my Ubuntu box).
ln-r () {
emulate -L zsh
local symlink
local -a here there route common
for symlink in $@:a
do
[[ -h $symlink ]] || continue
common=()
route=()
if [[ -d $symlink ]]
then here=( ${(s:/:)symlink} )
else here=( ${(s:/:)symlink:h} )
fi
there=( ${(s:/:)symlink:A} )
while (( $#here && $#there ))
do
if (( $#route))
then route=( .. $route $there[1] )
elif [[ $here[1] == $there[1] ]]
then
common+=( $here[1] )
else
if [[ -d $symlink || -z $common ]]
then route=( $there[1] )
else route=( .. $there[1] )
fi
fi
shift here
shift there
done
if (( $#common ))
then route+=( $there )
else continue # no common prefix, absolute link is best
fi
# Remove the "print" and both (qq) to actually do linking
print ln -fs "${(qq)${(j:/:)route}:-.}" "${(qq)symlink}"
done
}
To change the "no common prefix" behavior, change the loop to become
"while (( $#here || $#there ))" and remove references to $common.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author