From f2a778dd8fa2499d5a59639d064a37c8eec559ab Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sun, 13 Mar 2022 13:35:44 +0300 Subject: [PATCH] getrel without subshell calls --- zk.zsh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/zk.zsh b/zk.zsh index 94a6700..5a46d99 100755 --- a/zk.zsh +++ b/zk.zsh @@ -51,7 +51,22 @@ for p (${(k)backs}) { autoload -U relative getrel() { - relative $2:a $1:h + # nearly the copy-paste of Functions/Misc/relative + local dst=$2:a + local src=$1:h:a + local -a cur abs + cur=(${(s:/:)src}) + abs=(${(s:/:)dst:h} $dst:t) + integer i=1 + while [[ i -le $#abs && $abs[i] == $cur[i] ]] ; do + ((++i > $#cur)) && { + REPLY=${(j:/:)abs[i,-1]} + return + } + done + src=${(j:/:)cur[i,-1]/*/..} + dst=${(j:/:)abs[i,-1]} + REPLY=$src${dst:+/$dst} } genhtml() { -- 2.44.0