emacs-from-scratch icon indicating copy to clipboard operation
emacs-from-scratch copied to clipboard

Problems with Dired configuration on macOS

Open ricky9w opened this issue 3 years ago • 0 comments

ls on macOS does not support long-format options(such as --dired), as a result, the Dired configuration causes an error message like this:

Listing directory failed but 'access files' worked

Delete --group-directories-first argument can help get rid of this error, but a GNU-based ls which is exposed as gls by the coreutils formula can solve this problem. Here's my solution to this:

  1. install homebrew
  2. run brew install coreutils to install gls
  3. add some judgements to the Dired configuration:
(use-package dired
  :ensure nil
  :commands (dired dired-jump)
  :bind (("C-x C-j" . dired-jump))
  :config
  (when (string= system-type "darwin")
  (let ((gls (executable-find "gls")))
  (when gls
  (setq dired-use-ls-dired t
    insert-directory-program gls
    dired-listing-switches "-aBhl --group-directories-first")))))

Note that GUI applications and applications launched via shell see different environment variables on macOS, so executable -find function may not be able to find gls if you start Emacs by clicking the app icon or from spotlight. Thankfully a package called exec-path-from-shell can help. Here is the GitHub homepage for this package: https://github.com/purcell/exec-path-from-shell More info: https://stackoverflow.com/questions/8606954/path-and-exec-path-set-but-emacs-does-not-find-executable

ricky9w avatar Feb 08 '22 07:02 ricky9w