2022-10-22 16:35:03 +02:00
|
|
|
|
#!/bin/sh
|
|
|
|
|
set -e
|
2023-11-21 15:17:44 +01:00
|
|
|
|
|
2022-10-22 16:35:03 +02:00
|
|
|
|
getfsroot() {
|
2023-02-07 17:19:53 +01:00
|
|
|
|
printf "%s" "$(df "$1" --output=target | tail -1)"
|
2022-10-22 16:35:03 +02:00
|
|
|
|
}
|
|
|
|
|
list() {
|
2023-02-07 17:19:53 +01:00
|
|
|
|
# 1st arg is trash files directory
|
|
|
|
|
# 2nd arg is directory to match trash files for
|
2023-11-16 14:06:50 +01:00
|
|
|
|
[ ! "$(command ls -A "$1")" ] && exit 1
|
2023-11-24 15:46:14 +01:00
|
|
|
|
while read -r file; do
|
|
|
|
|
filepath=$(grep Path "$file" | cut -d '=' -f2) || continue
|
|
|
|
|
echo "$filepath" | grep -qP "^$2/[^/]+$" || continue
|
|
|
|
|
printf "%s %s %s\n" "$(basename "$file")" "$filepath" "$(date -d "$(grep DeletionDate "$file" | cut -d '=' -f2)" +'%x %X')"
|
|
|
|
|
done <<EOF
|
|
|
|
|
$(grep -l '[Trash Info]' "$1"/* "$1"/.* 2>/dev/null)
|
|
|
|
|
EOF
|
2022-10-22 16:35:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-21 15:17:44 +01:00
|
|
|
|
fsroot="$(getfsroot "$PWD")"
|
2023-11-16 14:06:50 +01:00
|
|
|
|
|
|
|
|
|
if [ "$fsroot" = "$(getfsroot "${XDG_DATA_HOME:-$HOME/.local/share}")" ]; then
|
|
|
|
|
basedir="${XDG_DATA_HOME:-$HOME/.local/share}/Trash"
|
|
|
|
|
else
|
2023-02-07 17:19:53 +01:00
|
|
|
|
basedir="${fsroot}/.Trash"
|
2023-11-16 14:06:50 +01:00
|
|
|
|
fi
|
2022-10-22 16:35:03 +02:00
|
|
|
|
|
2023-11-21 15:17:44 +01:00
|
|
|
|
sel="$(list "$basedir/info" "$PWD" | fzf)"
|
2023-11-16 14:06:50 +01:00
|
|
|
|
file="$basedir/files/$(echo "$sel" | cut -d '' -f1)"
|
|
|
|
|
dest="$(echo "$sel" | cut -d '' -f3)"
|
2023-11-24 15:46:14 +01:00
|
|
|
|
mv -ib "$file" "$dest"
|
|
|
|
|
rm "$basedir/info/$(echo "$sel" | cut -d '' -f1)"
|