kickingvegas / casual-dired

Casual Dired - An opinionated Transient user interface for Emacs file manager Dired.
GNU General Public License v3.0
124 stars 2 forks source link

Support sort by modified time on older version of ls v8.32 #29

Closed dandrake closed 3 months ago

dandrake commented 3 months ago

I use emacs on Windows, and casual-dired doesn't have the sort-by menu -- I see that the menu looks to casual-dired-show-sort-by-tmenu-p to decide when to show the sort-by menu.

I'm trying to search by modification time (or something similar) and would like to toggle reverse sorting, but it's not working for me.

Reverse sorting seems to work for name sorting, but not modification time. I do see, digging into the switches I think you're sending to ls:

$ ls --dired --sort=time  --time=modification
ls: invalid argument 'modification' for '--time'
Valid arguments are:
  - 'atime', 'access', 'use'
  - 'ctime', 'status'
  - 'birth', 'creation'
Try 'ls --help' for more information.

That's in my git bash, and I'm not 100% sure what emacs might be doing.

I'm sure this is somehow related to Windows, the particular ls programs I have on my machine, and something in my emacs config, but I thought I'd ask to see if there's any simple way to investigate/fiddle with this to get the time sorting working.

dandrake commented 3 months ago

aaaaaaand in classic fashion, nothing helps you figure out an issue better than publicly showing your ignorance and laziness. :)

I one reads the manual: https://www.gnu.org/software/emacs/manual/html_node/efaq-w32/Dired-ls.html, you can do something like

(setq ls-lisp-use-insert-directory-program t)      ;; use external ls
(setq insert-directory-program "c:/Program Files/Git/usr/bin/ls") ;; ls program name

and you get Git's bash. Now this mostly works -- I am seeing that using m gives the above error, but the other time-related options seem to work, and M (for metadata-changed) seems to reflect what I want. (I know that the Windows filesystem may record various times differently than the usual Linux/Unix-related filesystems.)

You may consider adding something about this to the manual?

kickingvegas commented 3 months ago

@dandrake looking at the man page for GNU coreutils 9.5 ls

 --time=WORD
              select which timestamp used to display or sort; access time
              (-u): atime, access, use; metadata change time (-c): ctime,
              status; modified time (default): mtime, modification; birth
              time: birth, creation;

              with -l, WORD determines which time to show; with --sort=time,
              sort by WORD (newest first)

It seems that the version of ls that you have does not support mtime, modification.

Perhaps finding an updated version can resolve this?

kickingvegas commented 3 months ago

@dandrake to help vet the Windows guidance, can I ask that you write a Show and Tell discussion item on how to configure GNU ls for Windows?

kickingvegas commented 3 months ago

@dandrake also, thanks much for the input! I don't have access to a Windows system so this input is very much appreciated!

kickingvegas commented 3 months ago

@dandrake Also what does ls --version return from your command line?

kickingvegas commented 3 months ago

Okay I think I have a handle on this. The current version (v1.0.3) of Casual Dired uses the ls command line switches for Coreutils 9.5. So this is legal.

ls --sort=time --time=modification

Problem is with earlier versions of ls, where modification or mtime is implicit/default behavior. To achieve the same effect with an older version of ls (in this case 8.32) you need to do this:

ls -t

Will make a patch with the following change to support compatibility with older versions of ls. Would appreciate it if you could apply this patch to verify this fix before I release.

modified   lisp/casual-dired-sort-by.el
@@ -209,8 +209,7 @@ See the man page `ls(1)' for details."

      ((eq criteria :date-modified)
       (message "Sorted by date modified")
-      (push "--sort=time" arg-list)
-      (push "--time=modification" arg-list))
+      (push "-t" arg-list))

      ((eq criteria :date-metadata-changed)
       (message "Sorted by date metadata changed")
dandrake commented 3 months ago

I have Git for Windows 2.43.0 installed. ls --version says:

$ ls --version
ls (GNU coreutils) 8.32

I tried your patch and it seems to work! Thanks! I'll look into a "show and tell" discussion.

kickingvegas commented 3 months ago

@dandrake Fantastic! I've just merged #30 which has the fix. Will push this out in v1.0.4.

kickingvegas commented 3 months ago

Release v1.0.4 made. This should be built on MELPA by EOD PDT May 7, 2024.

kickingvegas commented 3 months ago

Thank you @dandrake !

kickingvegas commented 3 months ago

v1.0.4 is live on MELPA https://melpa.org/#/casual-dired