dotfiles/.local/bin/scripts/m

18 lines
656 B
Plaintext
Raw Normal View History

2021-09-18 19:58:30 +00:00
#!/bin/sh -e
# Creates the last arg as directory (or its parent if not ending in a slash)
# and moves the preceding arguments into it.
# Automatically elevates if missing permissions.
2021-11-02 11:59:08 +00:00
for last; do true; done
2021-09-21 20:32:35 +00:00
checkaccess -w "$@" || elevate=sudo
2021-11-02 12:00:43 +00:00
! $elevate test -e "$1" && echo "$1 does not exist" && exit 1
dir="$(dirname "$1")"
2022-05-03 09:22:10 +00:00
test "$(lsattr -d "$dir" 2>/dev/null | cut -c6)" = a && setappend=true
test -z "$setappend" || sudo chattr -V -a "$dir"
2024-09-15 14:42:56 +00:00
$elevate mkdir -p "$(case "$last" in (*/) echo "$last";; (*) dirname "$last";; esac)"
$elevate mv --verbose --interactive "$@"
2022-05-11 10:34:28 +00:00
# TODO Diff when interactive
test -z "$setappend" || sudo chattr -V +a "$dir"