1
0
Fork 0
dotfiles/.local/bin/trash/trash-put-OLD

28 lines
776 B
Bash
Executable File

#!/bin/sh
set -e
getfsroot() {
printf "%s" "$(df "$1" --output=target | tail -1)"
}
filepath="$(realpath -s "$1")"
filename="$(basename "$1")"
fsroot="$(getfsroot "$1")"
[ "$fsroot" = "$(getfsroot "${XDG_DATA_HOME:-$HOME/.local/share}")" ] &&
basedir="${XDG_DATA_HOME:-$HOME/.local/share}/Trash" ||
basedir="${fsroot}/.Trash"
infodir="$basedir/info"
filedir="$basedir/files"
mkdir -p "$infodir" 1>/dev/null 2>&1
mkdir -p "$filedir" 1>/dev/null 2>&1
find "$filedir" -regex ".*$filename.*" | grep -oP '(?<=.\.~)\d+(?=~$)' | sort -n | tail -1 | (
ext=$(($(cat /dev/stdin) + 1))
filedest="$filedir/$filename.~$ext~"
command mv -f "$filepath" "$filedest"
cat <<EOF >"$infodir/$(basename "$filedest")"
[Trash Info]
Path=$filepath
DeletionDate=$(date -u +%Y%m%dUTC%T)
EOF
)