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