52 lines
1.2 KiB
Bash
Executable File
52 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -e
|
|
function helpexit() {
|
|
echo 'Delete files by moving to a safe in your ~/.cache/rm-safe
|
|
This command is always recursive!
|
|
|
|
-v verbose
|
|
--clear delete safe permanently
|
|
--status view safe sizes
|
|
'
|
|
exit
|
|
}
|
|
function clearsafe() {
|
|
test -d "$SAFELOC" && rm-progress -f "$SAFELOC"
|
|
exit
|
|
}
|
|
function viewsafe() {
|
|
test -d "$SAFELOC" && {
|
|
for d in "$SAFELOC"/*; do
|
|
printf "%s\t" "$d"
|
|
fastdu -h -s "$d"
|
|
done
|
|
}
|
|
exit
|
|
}
|
|
SAFELOC=~/.cache/rm-safe
|
|
FOLDERS=()
|
|
QUIET="-q"
|
|
[[ -z "$1" ]] && helpexit
|
|
for ((i=1; i<=${#@}; i++)) {
|
|
[[ "${!i}" = "-h" ]] && helpexit
|
|
[[ "${!i}" = "--help" ]] && helpexit
|
|
[[ "${!i}" = "-v" ]] && { VERBOSE=1; QUIET=""; continue; }
|
|
[[ "${!i}" = "--clear" ]] && { clearsafe; continue; }
|
|
[[ "${!i}" = "--status" ]] && { viewsafe; continue; }
|
|
[[ "${!i}" = "-"* ]] && helpexit
|
|
FOLDERS+=( "${!i}" )
|
|
}
|
|
mkdir -p "$SAFELOC"
|
|
now=$( date -Idate )
|
|
for d in "${FOLDERS[@]}"; do
|
|
if [[ ! -e "$d" ]]; then continue; fi
|
|
path=$( abs-path "$d" )
|
|
dir=$( dirname "$path" )
|
|
if [[ "$VERBOSE" -eq 1 ]]; then echo "$SAFELOC/$now/$path"; fi
|
|
if [[ -e "$SAFELOC/$now/$path" ]]; then file-version $QUIET "$SAFELOC/$now/$path"; fi
|
|
mkdir -p "$SAFELOC/$now/$dir"
|
|
mv "$d" "$SAFELOC/$now/$dir"
|
|
done
|
|
|