From 87e76cdc354040db4fad7cfbe69fa28c6e188c8b Mon Sep 17 00:00:00 2001 From: snailed Date: Fri, 21 Oct 2022 18:26:33 +0000 Subject: [PATCH] Create trash-restore A script to restore files trashed with trash-put using fzf --- .local/share/trash-restore | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .local/share/trash-restore diff --git a/.local/share/trash-restore b/.local/share/trash-restore new file mode 100644 index 00000000..aeb6f579 --- /dev/null +++ b/.local/share/trash-restore @@ -0,0 +1,25 @@ +#!/bin/sh +set -e +getfsroot() { + printf "%s" "$(df "$1" --output=target | tail -1)" +} +list() { + 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')" + done +} + +dir="${1:-$(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)" +file="$basedir/files/$(echo "$sel" | cut -d ' ' -f1)" +dest="$(echo "$sel" | cut -d ' ' -f2)" +command mv -ib "$file" "$dest"