From 97aa8204860cdbb9e8949c6ff263b15e554db994 Mon Sep 17 00:00:00 2001 From: Shiloh Fen Date: Mon, 23 Jun 2025 00:22:37 -0500 Subject: [PATCH] Add relink script Signed-off-by: Shiloh Fen --- README.md | 8 ++++++++ scripts/relink.nu | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100755 scripts/relink.nu diff --git a/README.md b/README.md index 19be49f..18c67af 100644 --- a/README.md +++ b/README.md @@ -57,3 +57,11 @@ Useful if you have multiple kernels installed. # lh-pairall Uses lighthouse_console to reset all SteamVR dongles, then put them all into pairing mode. + +# relink + +Update symlink targets from an old target directory to a new one + +Example: If you moved all files in `~/Development/tools` to `~/Applications`, you can update all +symlinks in `~/.local/bin` that point to the old location with +`relink ~/.local/bin ~/Development/tools ~/Applications` diff --git a/scripts/relink.nu b/scripts/relink.nu new file mode 100755 index 0000000..c11e952 --- /dev/null +++ b/scripts/relink.nu @@ -0,0 +1,31 @@ +#!/usr/bin/nu + +use std log + +# Update symlink targets from an old target directory to a new one +# +# Example: If you moved `~/Development/tools` to `~/Applications`, update all +# symlinks in `~/.local/bin` that point to the old location: +# `relink ~/.local/bin ~/Development/tools ~/Applications` +def main [ + directory: path + old_target_dir: path + new_target_dir: path +] { + let directory = $directory | path expand + let old_target_dir = $old_target_dir | path expand + let new_target_dir = $new_target_dir | path expand + + log info $"Updating symlinks in ($directory): ($old_target_dir)/.* -> ($new_target_dir)/.*" + + ls -l $directory + | where type == symlink and target starts-with $old_target_dir + | par-each {|link| + let new_target = $link.target | str replace ($old_target_dir + "/") ($new_target_dir + "/") + ln -sf $new_target $link.name + log info $"Updated ($link.name) target: ($link.target) -> ($new_target)" + } + + log info "Done!" +} + -- 2.51.2