38 lines
1.0 KiB
Bash
Executable File
38 lines
1.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -e
|
|
function helpexit() {
|
|
echo Delete files by moving to a safe location in your ~/.cache/rm-safe
|
|
echo This command is always recursive!
|
|
echo '-v verbose, --clear delete cache permanently'
|
|
exit
|
|
}
|
|
function clearsafe() {
|
|
test -d "$SAFELOC" && rm-progress -f "$SAFELOC"
|
|
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}" = "-"* ]] && helpexit
|
|
FOLDERS+=( "${!i}" )
|
|
}
|
|
mkdir -p "$SAFELOC"
|
|
now=$( date -Idate )
|
|
for d in "${FOLDERS[@]}"; do
|
|
if [[ ! -e "$d" ]]; then continue; fi
|
|
path=$( readlink -f "$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
|
|
|