bin: adjust bak to auto-elevate

This commit is contained in:
xeruf 2021-09-20 11:14:34 +02:00
parent f8d4fc9b4c
commit 79be21761e
2 changed files with 7 additions and 4 deletions

View File

@ -1,4 +1,4 @@
#!/bin/sh #!/bin/bash
# [b]rowse - custom ls or bat depending on file type # [b]rowse - custom ls or bat depending on file type
# Show type & contents of given files or PWD # Show type & contents of given files or PWD

View File

@ -1,9 +1,12 @@
#!/bin/sh #!/bin/sh
suffix="${2:-bak}" suffix="${2:-bak}"
orig="${1%%.$suffix}" orig="${1%%.$suffix}"
smv () {
test -w "$1" && mv -v "$@" || sudo mv -v "$@"
}
if test -e "$orig.$suffix" if test -e "$orig.$suffix"
then then
test -e "$orig" && mv -v "$orig" /tmp test -e "$orig" && smv "$orig" /tmp
mv -vn "$orig.$suffix" "$orig" smv -n "$orig.$suffix" "$orig"
else mv -vn "$1" "$1.$suffix" else smv -n "$1" "$1.$suffix"
fi fi