andreafrancia / trash-cli

Command line interface to the freedesktop.org trashcan.
GNU General Public License v2.0
3.58k stars 179 forks source link

RFE: Explicit the way of quitting trash-restore cleanly #271

Open jpggithub opened 1 year ago

jpggithub commented 1 year ago

The interactive prompt of trash-restore wait only for a number to do something. If we finally decide to not restore a file, what can we do?

I have discovered only recently that I could just strike return.

Before, I used Control+C that givent an ugly output ;-) something like:

What file to restore [0..1144]: ^CTraceback (most recent call last): File "/usr/bin/trash-restore", line 5, in <module> sys.exit(main()) File "/usr/lib/python3/dist-packages/trashcli/cmds.py", line 17, in restore ).run(sys.argv) File "/usr/lib/python3/dist-packages/trashcli/restore.py", line 50, in run self.handle_trashed_files(trashed_files) File "/usr/lib/python3/dist-packages/trashcli/restore.py", line 58, in handle_trashed_files self.restore_asking_the_user(trashed_files) File "/usr/lib/python3/dist-packages/trashcli/restore.py", line 60, in restore_asking_the_user index=self.input("What file to restore [0..%d]: " % (len(trashed_files)-1)) KeyboardInterrupt

The prompt could explicit the possible choices.

chapmanjacobd commented 1 year ago

One way to accomplish this is:

import signal
def exit_nicely(_signal, _frame):
    print("\nExiting... (Ctrl+C)")
    raise SystemExit(130)

signal.signal(signal.SIGINT, exit_nicely)

The trash-restore behavior when specifying a specific file also feels weird. In my mind it seems more intuitive if it was like this:

1) When specifying a specific file and there is only one match I feel trash-restore should use the "No news is good news" rule and output nothing, restore the file, and exit 0. 2) When specifying a specific file and there is no match, exit 1. (Right now it outputs "No files trashed from current dir ..." which is not relevant if the specified file is outside the current dir--it may just as well print nothing. But my feelings about printing a message is not as strong as in point 1) 3) When specifying a specific file and there are multiple matches keep the current behavior (restore_asking_the_user index list)