Update trash-restore

Add ability to set dir to search in
This commit is contained in:
snailed 2022-10-21 19:12:35 +00:00 committed by GitHub
parent 1d1d691f3a
commit e9097515ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,22 +4,26 @@ getfsroot() {
printf "%s" "$(df "$1" --output=target | tail -1)"
}
list() {
# 1st arg is trash files directory
# 2nd arg is directory to match trash files for
for file in "$1"/*; do
[ "$(head -1 "$file")" = "[Trash Info]" ] \
&& printf "%s %s %s\n" \
"$(basename "$file")" \
"$(grep Path "$file" | cut -d '=' -f2)" \
"$(date -d "$(grep Date "$file" | cut -d '=' -f2)" +'%x %X')"
[ "$(head -1 "$file")" = "[Trash Info]" ] && \
fpath=$(grep Path "$file" | cut -d '=' -f2) && \
echo "$fpath" | grep -qP "^$2" && \
printf "%s %s %s\n" \
"$(basename "$file")" \
"$fpath" \
"$(date -d "$(grep Date "$file" | cut -d '=' -f2)" +'%x %X')"
done
}
dir="${1:-$(getfsroot "$PWD")}"
[ -n "$1" ] && dir="$(realpath "$1")" || dir="$(getfsroot "$PWD")"
fsroot="$(getfsroot "$dir")"
[ "$fsroot" = "$(getfsroot "${XDG_DATA_HOME:-$HOME/.local/share}")" ] \
&& basedir="${XDG_DATA_HOME:-$HOME/.local/share}/Trash" \
|| basedir="${fsroot}/.Trash"
sel="$(list "$basedir/info" | fzf)"
sel="$(list "$basedir/info" "$dir" | fzf)"
file="$basedir/files/$(echo "$sel" | cut -d ' ' -f1)"
dest="$(echo "$sel" | cut -d ' ' -f2)"
command mv -ib "$file" "$dest"