3

I have set the ls program dired uses via

(setq insert-directory-program "gls"))

(so that I can specify --group-directories-first in dired-listing-switches).

Trouble is when I browse a remote directory, TRAMP seems to use the same variable insert-directory-program, but on arbitrary remote machines the gls command might not be available.

How can I set the ls program dired uses to gls only for local directories?

Drew
  • 75,699
  • 9
  • 109
  • 225
halloleo
  • 1,215
  • 9
  • 23
  • What (local) system are you running on? Have you built `gls` in e.g. `/usr/local/bin` with the system `ls` in `/usr/bin`? – NickD Sep 02 '21 at 20:14
  • @NickD Thanks for chiming in! I am on macOS Mojave (Intel) and installed GNU coreutils via Homebrew. So, yes, `gls` is in `/usr/local/bin` and the standard `ls` is in `/bin`. – halloleo Sep 03 '21 at 01:00
  • So you could set your PATH (and emacs's `exec-path`) to have `/usr/local/bin` first and rename `gls` to `ls`. Then restore the default for `insert-directory-program`: that way, you (and emacs) would get the `ls` that knows about `--group-directories-first` and you'd be happy and since you don't change the default, `tramp` would use that and everybody else would be happy too. People on your machine who have not set their PATH that way (either not including it at all or including it *after* `/bin`) would get the system `ls` and presumably they would be happy too. Any reason this wouldn't work? – NickD Sep 03 '21 at 03:12
  • @NickD That's probably the way to go. I just had hoped that there were separate variables for local and remote dired... – halloleo Sep 04 '21 at 12:36

1 Answers1

0

Elaborating on the comments form @NickD there seems to be no separate way to configure the used ls command used used for TRAMP directories vs local directories.

So the remaining option is to symlink the local gls (at least for Emacs) to ls and keep Emacs' default of insert-directory-program as "ls".

Update 28 Sep 2021:

Also, it is important to use no non-standard switches in dired-listing-switches, because they are used for the remote dired buffers as well! So stick with something like "-alhF" and don't use GNU's --group-directories-first, beacuse your TRAMP dired buffere will be empty when the remote system for example plain BSD.

halloleo
  • 1,215
  • 9
  • 23
  • Another option _might_ be to use `ls-lisp` instead of a OS-level `ls`, but I don't know what `ls-lisp` does for remote directories. - Will test it! – halloleo Sep 08 '21 at 01:13