sindresorhus / trash-cli

Move files and folders to the trash
MIT License
1.33k stars 35 forks source link

Add restore feature #15

Closed zaaack closed 7 years ago

zaaack commented 7 years ago

Like restore -last, restore -last=<n>, n means the last nth file/folder removed to trash.

sindresorhus commented 7 years ago

Blocked by https://github.com/sindresorhus/trash/issues/24 (Which is a long standing macOS bug...)

zaaack commented 7 years ago

@sindresorhus What a pity..

zaaack commented 7 years ago

@sindresorhus Can we store the original file's directory and just mv ~/.Trash/<lastFile> <lastDirectory>? I tried and it looks totally feasible.

sindresorhus commented 7 years ago

No, macOS renames duplicates in the trash, so original filenames are not guaranteed. The only workaround, as discussed in the original issue, is to parse the undocumented .DS_Store file, but that's not something I have time or interest in doing.

zaaack commented 7 years ago

@sindresorhus We can rename duplicates manually before putting to trash.

sindresorhus commented 7 years ago

That's a slippery slope. And our mapping will easily get out of sync when the user trashes and restores in Finder, which we can't know about.

zaaack commented 7 years ago

@sindresorhus But this wouldn't be a huge problem? We can rename with timestamp and rand id each time before moving to Trash, if the user restores in Finder, then it's handled by the user, he or she will know what he or she is doing since he is already using the command line. And if we cannot find the renamed file in Trash, we can print some message to show what happened.

sindresorhus commented 7 years ago

Yes, I guess that would work, but it's not something I would be interested in maintaining.

zaaack commented 7 years ago

@sindresorhus Fair enough.