summary refs log tree commit diff stats
path: root/user/zsh/zshrc
diff options
context:
space:
mode:
authorAlan Pearce2023-04-12 11:59:38 +0200
committerAlan Pearce2023-04-12 11:59:38 +0200
commitee51c126d95515cc6bc4c5109a225ccf559dc516 (patch)
tree43100ac12a4945e8237229844bfa395d5a8eaeec /user/zsh/zshrc
parent987d8c5d2a25ece7ee2f06046cb0480047ddef08 (diff)
downloadnixfiles-ee51c126d95515cc6bc4c5109a225ccf559dc516.tar.lz
nixfiles-ee51c126d95515cc6bc4c5109a225ccf559dc516.tar.zst
nixfiles-ee51c126d95515cc6bc4c5109a225ccf559dc516.zip
zsh: add `delink` function to replace a symlink with a copy
Diffstat (limited to 'user/zsh/zshrc')
-rw-r--r--user/zsh/zshrc12
1 files changed, 12 insertions, 0 deletions
diff --git a/user/zsh/zshrc b/user/zsh/zshrc
index cd5a4986..6a60a060 100644
--- a/user/zsh/zshrc
+++ b/user/zsh/zshrc
@@ -26,6 +26,18 @@ field () {
 }
 alias f=field
 
+delink () {
+  if [[ ! -h "$1" ]]
+  then
+    echo "$1 is not a symlink"
+    return 1
+  fi
+  local src=$(readlink "$1")
+  rm "$1"
+  cp "$src" "$1"
+  chmod u+w "$1"
+}
+
 backward-argument () {
   local WORDCHARS="\!\`~#@$%^&*()-_=+[{]}\|;:,<.>/?\'\""
   zle backward-word