From f193e0071dd284f5071589668a99a65d4a3a2ee4 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Mon, 10 Jul 2023 14:03:50 +0200 Subject: [PATCH] zsh:mvln(): Revert "Create relative symlinks" This reverts commit 226f09b04613dbc7bbd83e8016f7e8b02544c269. I don't want to have relative links all the time. TODO: If target is a relative path, make the link relative too TODO: Support --relative flag --- .config/zsh/zshrc.d/40-functions.zsh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.config/zsh/zshrc.d/40-functions.zsh b/.config/zsh/zshrc.d/40-functions.zsh index 4076fbb..4ed414f 100644 --- a/.config/zsh/zshrc.d/40-functions.zsh +++ b/.config/zsh/zshrc.d/40-functions.zsh @@ -340,7 +340,7 @@ if (( $+commands[trash] )); then } fi -# Move one or more file(s) but keep a relative symlink to the new location. +# Move one or more file(s) but keep a symlink to the new location. mvln() { if (( # < 2 )); then printf "$0: missing file operand\n" @@ -358,7 +358,10 @@ mvln() { local file reg=0 for file in "${@[1,-2]}"; do - target="${@[-1]}" + # NOTE: We need absolute paths here for executions like `$0 foo/bar .` + # TODO: When do we want/can we use relative links? Only when file is in + # current dir? + target="${@[-1]:A}" # If the target is a directory, `file` will end up in it [[ ! -d ${@[-1]} ]] || target+="/$file:t" @@ -368,7 +371,7 @@ mvln() { fi # NOTE: `ln` does not like trailing slashes on the last argument - ln -sr "$target" "${file%/}" + ln -s "$target" "${file%/}" done return $reg