From e9097515ce3041ab22709e9fe43aeee1d878160b Mon Sep 17 00:00:00 2001 From: snailed Date: Fri, 21 Oct 2022 19:12:35 +0000 Subject: [PATCH] Update trash-restore Add ability to set dir to search in --- .local/share/trash-restore | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/.local/share/trash-restore b/.local/share/trash-restore index aeb6f579..0b2db442 100644 --- a/.local/share/trash-restore +++ b/.local/share/trash-restore @@ -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"