From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10701 invoked by alias); 6 Mar 2016 19:38:32 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 21366 Received: (qmail 5948 invoked from network); 6 Mar 2016 19:38:30 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version; bh=NuX9DpPLihSuq87e+qa0Jx1j6bPM9RJAZVgZEJnAPYg=; b=lHKk/quP4qMd9ipGKrnyQGpkfOSoRtjIvpiHciwgw8Xavmrh5yGddLTxPjRsZCmC+y VGnuSrMWbkE7QEpEaHg0uI/kDdZ2cwIqr7ZoS7IVeOq5Hg7DLOL93V20wWTj/jBotZRp 2VgJmosUpMZzo8TNEwCOOvzsn/bEF+dsrPTK4/OG2TPIpYlnNSC5XQubfZrUq5yoI8W9 OLxMKTMZOSOvYps2XOqoz6xbCxlT0f2AHFGO7/NGBJQr+1zsr2hhf5klxmsz4bI00zFa 7feW0zxZ6/coLLy5YOalMqSPp7xMyY3+sIUuQReA6RY77SuAdjBglgfCRyn4g9f+3jDC 0P7g== X-Gm-Message-State: AD7BkJJi9Ec2tCpNcFKvTBV5sL00TcElLNCXev7tEMlU+gNqi6pEAQCoevIa4LxOEwiN0g== X-Received: by 10.66.55.39 with SMTP id o7mr27815165pap.13.1457293108533; Sun, 06 Mar 2016 11:38:28 -0800 (PST) From: Bart Schaefer Message-Id: <160306113830.ZM2800@torch.brasslantern.com> Date: Sun, 6 Mar 2016 11:38:30 -0800 In-Reply-To: <20160306173915.GC10755@lorien.comfychair.org> Comments: In reply to Danek Duvall "Re: Converting absolut symlinks to relative ones...?" (Mar 6, 9:39am) References: <20160306132013.GA4938@solfire> <20160306173915.GC10755@lorien.comfychair.org> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: Converting absolut symlinks to relative ones...? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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.