summary refs log tree commit diff stats
path: root/user
diff options
context:
space:
mode:
authorAlan Pearce2023-04-25 21:43:02 +0200
committerAlan Pearce2023-04-25 21:43:02 +0200
commit9389e4954b12c12b2f020236bd6642f238ec8c9b (patch)
treebe5ad8427118ec518b3c98cf70ccbc07b8d17989 /user
parentcb9dbecb7080f5989e5bcc07959c719ee05cea81 (diff)
downloadnixfiles-9389e4954b12c12b2f020236bd6642f238ec8c9b.tar.lz
nixfiles-9389e4954b12c12b2f020236bd6642f238ec8c9b.tar.zst
nixfiles-9389e4954b12c12b2f020236bd6642f238ec8c9b.zip
zsh: add function to move a file and replace it with a link
Diffstat (limited to 'user')
-rw-r--r--user/zsh/zshrc20
1 files changed, 20 insertions, 0 deletions
diff --git a/user/zsh/zshrc b/user/zsh/zshrc
index 6a60a060..831ada1e 100644
--- a/user/zsh/zshrc
+++ b/user/zsh/zshrc
@@ -38,6 +38,26 @@ delink () {
   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