From: Sergey Matveev Date: Sun, 13 Mar 2022 10:35:44 +0000 (+0300) Subject: getrel without subshell calls X-Git-Url: http://www.git.stargrave.org/?p=zk.zsh.git;a=commitdiff_plain;h=f2a778dd8fa2499d5a59639d064a37c8eec559ab getrel without subshell calls --- 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() {