Introducing trash-u (File::Trash::Undoable)

Python has trash-cli, Bash has rmv, now Perl has trash-u (from File::Trash::Undoable, which in turns wraps File::Trash::FreeDesktop).

To trash your files:

% trash-u foo.tmp *.bak

To see the contents of your trash:

% trash-u --list-contents

To empty your trash:

% trash-u --empty

Unlike trash-cli (and like rmv), trash-u supports undo (called rollback in rmv). And unlike rmv, trash-u supports redo. Multiple undo/redo is supported. It's also worth noting that rmv currently does not support per-filesystem trash (everything goes to $HOME, which might cause heavy copying between devices).

To undo your last action:

% trash-u --undo

And to redo:

% trash-u --redo

To see your actions history:

% trash-u --history

To discard history (forget undo/redo information):

% trash-u --clear-history

trash-u also supports dry-run mode to show what's going to be deleted:

% trash-u foo.tmp *.bak --dry-run --verbose

Some notes:

  • New module, not much tested yet, be careful with your files.

  • The trash-u utility is originally written to demonstrate the Rinci undo and transaction protocol. The utility requires SQLite to store transaction information. There's another simpler demonstration script symlink-u to setup/unsetup symlinks, distributed along with Perinci::CmdLine.

  • File::Trash::FreeDesktop, which provides the actual trashing routines, was written from scratch and reading the freedesktop.org spec to first CPAN release in about 3.5 hours.

  • Writing File::Trash::Undoable and trash-u utility from scratch to first CPAN release requires just around 2 hours of coding time. This is because the undo and command-line framework already do the hard work (providing --undo, --redo, --history, --clear-history, --dry-run, and --help).

  • Tweaking and polishing further will take extra time, though.

Leave a comment

About Steven Haryanto

user-pic A programmer (mostly Perl 5 nowadays). My CPAN ID: SHARYANTO. I'm sedusedan on perlmonks. My twitter is stevenharyanto (but I don't tweet much). Follow me on github: sharyanto.