dotfiles/.local/bin/scripts/bak

18 lines
295 B
Text
Raw Normal View History

#!/bin/sh
2021-07-04 18:20:36 +02:00
suffix="${2:-bak}"
2021-07-04 21:56:12 +02:00
orig="${1%%.$suffix}"
2021-09-20 11:14:34 +02:00
smv () {
2021-09-29 18:38:57 +02:00
eval source=\$$(($#-1))
2021-10-22 17:15:09 +02:00
if test -w "$source"
then mv -v "$@"
else sudo mv -v "$@"
fi
2021-09-20 11:14:34 +02:00
}
2021-07-04 21:56:12 +02:00
if test -e "$orig.$suffix"
then
2021-09-20 11:14:34 +02:00
test -e "$orig" && smv "$orig" /tmp
smv -n "$orig.$suffix" "$orig"
2021-09-29 18:38:57 +02:00
else
smv -n "$1" "$1.$suffix"
2021-07-04 21:56:12 +02:00
fi