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"