From 491907484de11327494ffae8aa92e3f9cb3790a4efdc858222726b477c5f645c Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Thu, 21 Mar 2024 23:54:10 +0300 Subject: [PATCH] No Perl dependency for relative path calculation --- dep-add | 2 +- lib.zsh.rc | 4 +--- recfile-export | 5 ++++- show | 5 ++++- tag-add | 4 +++- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/dep-add b/dep-add index 819a466..4e3c7a0 100755 --- a/dep-add +++ b/dep-add @@ -17,5 +17,5 @@ dst=$dst:a src=$src:a mkdir -p $dst/deps cd $dst/deps -ln -f -s `relpath $src .` +ln -f -s `relative $src:h`/$src:t git add $src:t diff --git a/lib.zsh.rc b/lib.zsh.rc index fcb1cd3..e4b582b 100644 --- a/lib.zsh.rc +++ b/lib.zsh.rc @@ -10,9 +10,7 @@ die() { [[ -d issues ]] || die You must run that command in directory with issues/ -relpath() { - $PERL -mFile::Spec -le "print File::Spec->abs2rel(@ARGV)" $1:a $2:a -} +autoload -Uz relative endash() { $PERL -npe 's/(-+)/$1-/g ; s/ /-/g' diff --git a/recfile-export b/recfile-export index 429c177..2d5f070 100755 --- a/recfile-export +++ b/recfile-export @@ -9,7 +9,10 @@ print Issue: $issue print Project: $issue:h print Name: `print $issue:t | dedash` for tag (`$root/tag-list $issue`) print Tag: $tag -for dep (issues/$issue/deps/*(N)) print Depends: $(relpath $(realpath $dep) issues) +for dep (issues/$issue/deps/*(N)) { + _dep=$(relative $(realpath $dep)) + print Depends: ${_dep#issues/} +} print About: sed "s/^/+ /" < issues/$issue/about print Result: diff --git a/show b/show index b58f03b..e405bde 100755 --- a/show +++ b/show @@ -11,7 +11,10 @@ deps=(issues/$issue/deps/*(N)) [[ ${#deps} -eq 0 ]] || { delim print Depends on: - for dep ($deps) print "\t"$(relpath $(realpath $dep) issues) + for dep ($deps) { + _dep=$(relative $(realpath $dep)) + print "\t"${_dep#issues/} + } } delim cat issues/$issue/about diff --git a/tag-add b/tag-add index 60d144d..e6bf85d 100755 --- a/tag-add +++ b/tag-add @@ -15,6 +15,8 @@ for tag ($@) { tag=$tag:a [[ -r $tag ]] || die Unknown tag mkdir -p issues/$issue/tags - ln -f -s `relpath $tag issues/$issue/tags` issues/$issue/tags/$tag:t + ln -f -s \ + `cd issues/$issue/tags ; relative $tag:h`/$tag:t \ + issues/$issue/tags/$tag:t git add issues/$issue/tags/$tag:t } -- 2.44.0