From 771d5a041a48b4ebf2c5ee8ff2fc98834a613843 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 12 Dec 2015 16:48:02 -0500 Subject: bash: improve the mvln function --- .config/bash/rc.d/10_aliases.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.config/bash/rc.d/10_aliases.sh b/.config/bash/rc.d/10_aliases.sh index d6a1ab3..f34230b 100644 --- a/.config/bash/rc.d/10_aliases.sh +++ b/.config/bash/rc.d/10_aliases.sh @@ -82,15 +82,23 @@ term-title() { printf "$fmt" "$*" } mvln() { + local target link if [[ ! -L "$1" ]]; then libremessages error 'Not a soft link: %s' "$1" + return 1 fi - target=$(readlink -f -- "$1") - ln -srT -- "$target" "$2" - if cmp -- "$1" "$2"; then + if [[ -d "$2" ]]; then + link="$2/${1##*/}" + else + link="$2" + fi + target=$(readlink -f -- "$1") || return 1 + ln -srT -- "$target" "$link" + if cmp -- "$1" "$link"; then rm -f -- "$1" else - libremessages error 'Failed moving link: %s -> %s' "$1" "$2" + libremessages error 'Failed moving link: %s -> %s' "$1" "$link" + return 1 fi } jarls() { -- cgit v1.2.3