trash-cli
trash-cli copied to clipboard
Please consider trash-undo
I guess this would require that the trash-put command cache the list of files removed at its last invocation (or a diff of trash-list before and after), but it would be great to be able to undo (i.e. trash-restore) everything I just trashed without thinking when I don't know the name of the file I need to get back.
For people in the future, here's a one liner that does the equivalent procedure using only coreutils:
echo '' | trash-restore 2>/dev/null | sed '$d' | sort -k2,3 -k1,1n | awk 'END {print $1}' | trash-restore >/dev/null 2>&1
trash-restore's ordering is consistent, but not chronological.
- We generate the numbered list by feeding an empty option to
trash-restore - Remove the extra line at the end
- To find the most recent element, we first sort by date (2), then time (3), then the index (1) in ascending order
- Take the last one
- We then feed that into
trash-restoreand get a restore.
The only edge case is if trash-restore is empty, but in that case, we end up feeding an empty line into trash-restore again, so nothing happens.
Also, you can drop in an fzf or dmenu in the middle there and make it an interactive restoration:
echo '' | trash-restore 2>/dev/null \
| sed '$d' \
| sort -k2,3 -k1,1n \
| dmenu \
| awk 'END {print $1}' \
| trash-restore >/dev/null 2>&1