« get me outta code hell

zsh: relink utility - dotfiles - Miscellaneous configuration files of my personal use
about summary refs log tree commit diff
path: root/.zshrc
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2025-01-20 11:08:20 -0400
committer(quasar) nebula <qznebula@protonmail.com>2025-05-05 19:05:41 -0300
commit1b9d01dd5219e4547eaa3847f49ec94960bb491b (patch)
tree5555b615099665949ef3b36bbb43840caab2bf06 /.zshrc
parent7ec3e2724ff6b43e3da88815fd1d47e6e59bdfcd (diff)
zsh: relink utility
Diffstat (limited to '.zshrc')
-rw-r--r--.zshrc16
1 files changed, 16 insertions, 0 deletions
diff --git a/.zshrc b/.zshrc
index 3c92d3b..6f01d13 100644
--- a/.zshrc
+++ b/.zshrc
@@ -115,6 +115,22 @@ export PATH
 
 # //// aliases & non-script functions //////////////////////// <alias-fns> // #
 
+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