rmmsafe
This commit is contained in:
36
files/rm-safe
Executable file
36
files/rm-safe
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/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=()
|
||||
[[ -z "$1" ]] && helpexit
|
||||
for ((i=1; i<=${#@}; i++)) {
|
||||
[[ "${!i}" = "-h" ]] && helpexit
|
||||
[[ "${!i}" = "--help" ]] && helpexit
|
||||
[[ "${!i}" = "-v" ]] && { VERBOSE=1; 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 "$path"; fi
|
||||
if [[ -e "$SAFELOC/$now/$path" ]]; then file-version -q "$SAFELOC/$now/$path"; fi
|
||||
mkdir -p "$SAFELOC/$now/$dir"
|
||||
mv "$d" "$SAFELOC/$now/$dir"
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user