summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2015-12-12 16:48:02 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2015-12-12 17:20:15 -0500
commit771d5a041a48b4ebf2c5ee8ff2fc98834a613843 (patch)
tree01c5fa425f9a6d061beec66f9f9815b27b1a6930
parentc9daeaee779e50ed84b03a34914ebf940aa7993c (diff)
bash: improve the mvln function
-rw-r--r--.config/bash/rc.d/10_aliases.sh16
1 files 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() {