From 226f09b04613dbc7bbd83e8016f7e8b02544c269 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Thu, 9 Feb 2023 17:04:19 +0100 Subject: [PATCH] zsh:mvln(): Create relative symlinks When using ln's `-a` flag, absolute paths are not necessary. --- .config/zsh/zshrc.d/40-functions.zsh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.config/zsh/zshrc.d/40-functions.zsh b/.config/zsh/zshrc.d/40-functions.zsh index a40342d..88e1d7d 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 symlink to the new location. +# Move one or more file(s) but keep a relative symlink to the new location. mvln() { if (( # < 2 )); then printf "$0: missing file operand\n" @@ -358,10 +358,7 @@ mvln() { local file reg=0 for file in "${@[1,-2]}"; do - # 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}" + target="${@[-1]}" # If the target is a directory, `file` will end up in it [[ ! -d ${@[-1]} ]] || target+="/$file:t" @@ -371,7 +368,7 @@ mvln() { fi # NOTE: `ln` does not like trailing slashes on the last argument - ln -s "$target" "${file%/}" + ln -sr "$target" "${file%/}" done return $reg