How do I restore a file from trash? #667
Replies: 2 comments 8 replies
-
If you are on macOS/Windows, they will go into the system's trash/recycle bin, where you can recover them. If you are on Linux, it will follow The FreeDesktop.org Trash specification and go into the directory specified by that specification. Most desktop environments adhering to this specification will abstract out a trash/recycle bin concept similar to macOS/Windows. Of course, the best approach is to avoid accidental deletion. See the doc here https://yazi-rs.github.io/docs/configuration/keymap/#remove |
Beta Was this translation helpful? Give feedback.
-
Thanks for your suggestion. I wrote a shell script to do it for me. #!/bin/sh
# List deleted files/directories in $PWD using `fzf` and restore the selected ones.
deleted="$(printf "\n" | trash-restore |
head -n -1 |
awk -v filter="^${PWD}/[^/]*$" '$4~filter {print $1, $4}')"
ids="$(echo "$deleted" | fzf --multi | cut -d' ' -f1 | tr '\n' ',')"
ids="${ids%,}"
echo "$ids" | exec trash-restore >/dev/null Since this script isn't actually required outside of yazi, I wish to inline it in I tried this but it doesn't work. [[manager.prepend_keymap]]
desc = "Restore file"
on = ["R"]
exec = '''
shell 'deleted="$(printf "\n" | trash-restore | head -n -1 | awk -v filter="^${PWD}/[^/]*$" '$4~filter {print $1, $4}')"
ids="$(echo "$deleted" | fzf --multi | cut -d' ' -f1 | tr '\n' ',')"
ids="${ids%,}"
echo "$ids" | exec trash-restore >/dev/null' --block --confirm
''' |
Beta Was this translation helpful? Give feedback.
-
Is there any way I can restore an accidentally deleted file that went to trash?
Beta Was this translation helpful? Give feedback.
All reactions