From 7739d0a9c36b990a30f362129e13a5ca82eed589 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Thu, 9 Feb 2023 17:02:05 +0100 Subject: [PATCH] zsh:mvln(): Refactor to fewer lines and zshisms --- .config/zsh/zshrc.d/40-functions.zsh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.config/zsh/zshrc.d/40-functions.zsh b/.config/zsh/zshrc.d/40-functions.zsh index fe2e1db..a40342d 100644 --- a/.config/zsh/zshrc.d/40-functions.zsh +++ b/.config/zsh/zshrc.d/40-functions.zsh @@ -358,15 +358,13 @@ mvln() { local file reg=0 for file in "${@[1,-2]}"; do - # If the target is a directory, `file` will end up in it # 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? - if [[ -d ${@[-1]} ]]; then - target="${@[-1]:A}/$(basename "$file")" - else - target="${@[-1]:A}" - fi + target="${@[-1]:A}" + # If the target is a directory, `file` will end up in it + [[ ! -d ${@[-1]} ]] || target+="/$file:t" + if ! command mv -i "$file" "${@[-1]}"; then reg=1 continue