mirror of
https://github.com/LukeSmithxyz/voidrice.git
synced 2026-03-20 01:37:45 +01:00
Create trash-restore
A script to restore files trashed with trash-put using fzf
This commit is contained in:
parent
d63a37f7ad
commit
87e76cdc35
25
.local/share/trash-restore
Normal file
25
.local/share/trash-restore
Normal file
@ -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"
|
||||
Loading…
x
Reference in New Issue
Block a user