dotfiles/.local/bin/scripts/m

18 lines
649 B
Bash
Executable File

#!/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.
for last; do true; done
checkaccess -w "$@" || elevate=sudo
! $elevate test -e "$1" && echo "$1 does not exist" && exit 1
dir="$(dirname "$1")"
test "$(lsattr -d "$dir" | cut -c6 2>/dev/null)" = a && setappend=true
test -z "$setappend" || sudo chattr -V -a "$dir"
$elevate mkdir -p $(case "$last" in (*/) echo "$last";; (*) dirname "$last";; esac)
$elevate mv --verbose --interactive "$@"
# Diff when interactive
test -z "$setappend" || sudo chattr -V +a "$dir"