From 121900c093c2a7101539ea18a8ea447b09e463fd Mon Sep 17 00:00:00 2001 From: druckdev <63563978+druckdev@users.noreply.github.com> Date: Tue, 3 Nov 2020 14:23:54 +0100 Subject: [PATCH] zsh: Add mvln() that moves a file but keeps a link --- .config/zsh/plugins/functions.zsh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.config/zsh/plugins/functions.zsh b/.config/zsh/plugins/functions.zsh index 39f6a0e..7d80c7a 100644 --- a/.config/zsh/plugins/functions.zsh +++ b/.config/zsh/plugins/functions.zsh @@ -310,3 +310,16 @@ nemo() { command nemo "$@" fi } + +## Move a file but keep a symlink to the new location. +mvln() { + # DST will not exist if `mv` is used for renaming. + [[ -e $1 ]] && [[ -d $2 || -d "$(dirname "$2")" ]] || return 1 + + mv "$1" "$2" || return + if [[ -d $2 ]]; then + ln -s "${2:A}/$(basename "$1")" "$1" + else + ln -s "${2:A}" "$1" + fi +}