2022-10-22 16:35:03 +02:00
|
|
|
|
#!/bin/sh
|
2023-11-16 14:06:50 +01:00
|
|
|
|
|
2022-10-22 16:35:03 +02:00
|
|
|
|
set -e
|
|
|
|
|
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-02-07 17:19:53 +01:00
|
|
|
|
for file in "$1"/*; do
|
|
|
|
|
[ "$(head -1 "$file")" = "[Trash Info]" ] &&
|
2023-11-16 14:06:50 +01:00
|
|
|
|
filepath=$(grep Path "$file" | cut -d '=' -f2) &&
|
|
|
|
|
echo "$filepath" | grep -qP "^$2/[^/]+$" &&
|
|
|
|
|
printf "%s %s %s\n" \
|
2023-02-07 17:19:53 +01:00
|
|
|
|
"$(basename "$file")" \
|
2023-11-16 14:06:50 +01:00
|
|
|
|
"$filepath" \
|
2023-02-07 17:19:53 +01:00
|
|
|
|
"$(date -d "$(grep Date "$file" | cut -d '=' -f2)" +'%x %X')"
|
|
|
|
|
done
|
2022-10-22 16:35:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-16 14:06:50 +01:00
|
|
|
|
if [ -n "$1" ]; then
|
|
|
|
|
dir="$(realpath "$1")"
|
|
|
|
|
else
|
|
|
|
|
dir="$(realpath "$PWD")"
|
|
|
|
|
fi
|
|
|
|
|
|
2022-10-22 16:35:03 +02:00
|
|
|
|
fsroot="$(getfsroot "$dir")"
|
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
|
|
|
|
|
|
|
|
|
sel="$(list "$basedir/info" "$dir" | fzf)"
|
2023-11-16 14:06:50 +01:00
|
|
|
|
file="$basedir/files/$(echo "$sel" | cut -d '' -f1)"
|
|
|
|
|
dest="$(echo "$sel" | cut -d '' -f3)"
|
2022-10-22 16:35:03 +02:00
|
|
|
|
command mv -ib "$file" "$dest"
|
2023-11-16 14:06:50 +01:00
|
|
|
|
command rm "$basedir/info/$(echo "$sel" | cut -d '' -f1)"
|