From 1b9d01dd5219e4547eaa3847f49ec94960bb491b Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 20 Jan 2025 11:08:20 -0400 Subject: zsh: relink utility --- .zshrc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.zshrc b/.zshrc index 3c92d3b..6f01d13 100644 --- a/.zshrc +++ b/.zshrc @@ -115,6 +115,22 @@ export PATH # //// aliases & non-script functions //////////////////////// // # +relink() { + inode1=$(ls -i $1 | cut -d " " -f 1) && + inode2=$(ls -i $2 | cut -d " " -f 1) && + if [[ $inode1 == $inode2 ]]; then + echo files are already same inode >&2 + else + sha1=$(sha256sum $1 | cut -d " " -f 1) && + sha2=$(sha256sum $2 | cut -d " " -f 1) && + if [[ $sha1 != $sha2 ]]; then + echo files have different checksums >&2 + else + rm $2 && ln $1 $2 + fi + fi +} + # -- hooks into third-party stuff -- if [[ -v DEVICE_HAS_VIM ]]; then -- cgit 1.3.0-6-gf8a5