all repos — nixfiles @ 9389e4954b12c12b2f020236bd6642f238ec8c9b

System and user configuration, managed by nix and home-manager

zsh: add function to move a file and replace it with a link
Alan Pearce alan@alanpearce.eu
Tue, 25 Apr 2023 21:43:02 +0200
commit

9389e4954b12c12b2f020236bd6642f238ec8c9b

parent

cb9dbecb7080f5989e5bcc07959c719ee05cea81

1 files changed, 20 insertions(+), 0 deletions(-)

jump to
M user/zsh/zshrcuser/zsh/zshrc
@@ -38,6 +38,26 @@ cp "$src" "$1"   chmod u+w "$1"
 }
 
+mvlink () {
+	src="$1"
+	target="$2"
+	if [[ -h "$src" ]]
+	then
+		echo "$src is already a symlink"
+		return src
+	fi
+	if [[ -f "$target" ]]
+	then
+		echo "$target already exists"
+	fi
+	if [[ -d "$target" ]]
+	then
+		target="$target/$(basename $src)"
+	fi
+	mv "$src" "$target"
+	ln -s "$target" "$src"
+}
+
 backward-argument () {
   local WORDCHARS="\!\`~#@$%^&*()-_=+[{]}\|;:,<.>/?\'\""
   zle backward-word