From bf330db8d9d503c26fee54ec3d1f29cc0d0fda09 Mon Sep 17 00:00:00 2001 From: David Luevano Alvarado Date: Tue, 16 Mar 2021 21:37:40 -0700 Subject: Add new sbg command, based on ssg, rssg and lb, wip --- .local/bin/ssg | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to '.local/bin/ssg') diff --git a/.local/bin/ssg b/.local/bin/ssg index 5c26190..2b4a4ec 100755 --- a/.local/bin/ssg +++ b/.local/bin/ssg @@ -30,6 +30,8 @@ main() { test -d "$1" || no_dir "$1" test -d "$2" || no_dir "$2" + # Convert src and dst to full paths, + # avoiding symlinks. src=$(readlink_f "$1") dst=$(readlink_f "$2") @@ -131,15 +133,25 @@ main() { readlink_f() { + # $1 = src or dst + file="$1" + # Go to the root of the blog (strips dst or src from path) cd "$(dirname "$file")" + # Only get the directory name (src or dst) file=$(basename "$file") + + # Tests if src or dst is a symbolic link, + # in which case resolves the symbolic link (readlink) + # and gets the actual directories. while test -L "$file" do file=$(readlink "$file") cd "$(dirname "$file")" file=$(basename "$file") done + + # Avoid all symbolic links and return the actual path. dir=$(pwd -P) echo "$dir/$file" } -- cgit v1.2.3-70-g09d2