andreafrancia / trash-cli

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

sort the output of trash-list by DeletionDate first #266

Open Susensio opened 1 year ago

Susensio commented 1 year ago

When I do trash-list, the sorting is unexpected. It is not sorted alphabetically nor by deletion date. Is there something I am missing here?

andreafrancia commented 1 year ago

At the moment no sorting is implemented in trash-list, the files were shown as they are provided from the file system.

In order to change this behaviour you need to change the list_trash method in list.py:

    def list_trash(self,
                   user_specified_trash_dirs,
                   extractor,
                   show_files,
                   all_users,
                   environ,
                   uid):
        trash_dirs = self.selector.select(all_users,
                                          user_specified_trash_dirs,
                                          environ,
                                          uid)
        for event, args in trash_dirs:
            if event == trash_dir_found:
                path, volume = args
                trash_dir = TrashDirReader(self.file_reader)
                for trash_info in trash_dir.list_trashinfo(path):
                    self._print_trashinfo(volume, trash_info, extractor,
                                          show_files)
            elif event == trash_dir_skipped_because_parent_not_sticky:
                path, = args
                self.output.top_trashdir_skipped_because_parent_not_sticky(path)
            elif event == trash_dir_skipped_because_parent_is_symlink:
                path, = args
                self.output.top_trashdir_skipped_because_parent_is_symlink(path)
jpggithub commented 1 year ago

I think it will me useful to have options to trash-restore ou trash-list to sort the results alphabetically (a to z, or z to a) or by deletion date (more recent first or less recent first).

By the way, I tried the change proposed but it didn't work for me. Can you give a diff -u or a new list.py? (I'm not a python expert ;-)

EDIT: I have the following error. Traceback (most recent call last): File "/usr/bin/trash-list", line 5, in <module> sys.exit(main()) File "/usr/lib/python3/dist-packages/trashcli/cmds.py", line 45, in list ListCmd( File "/usr/lib/python3/dist-packages/trashcli/list.py", line 37, in run parse(argv) File "/usr/lib/python3/dist-packages/trashcli/trash.py", line 110, in __call__ self.default_action() TypeError: ListCmd.list_trash() missing 6 required positional arguments: 'user_specified_trash_dirs', 'extractor', 'show_files', 'all_users', 'environ', and 'uid'