0

I would like to hide dotfiles only in the home directory in dired buffers, but I do not know how to achieve this. I have been trying with the following:

(use-package dired
  :ensure nil
  :commands (dired dired-jump)
  :bind (("C-x C-j" . dired-jump)
         (:map dired-mode-map ("C-c h" . dired-omit-mode)))
  :config
  (setq dired-omit-files (rx (seq bol "."))) ; hide dotfiles in dired-omit-mode

  (defun najjt/dired-after-readin ()
    "Turn on dired-omit-mode if current buffer is a dired buffer in the home directory."
    (if (string-equal (buffer-name) "najjt") ; check if current buffer name is equal to name of home dir
        (dired-omit-mode 1)
      (dired-omit-mode nil)))

  :hook ((dired-after-readin . (lambda () (najjt/dired-after-readin))))
  )

But it seems to hide dotfiles in all directories, not just my home directory.

1
  • 3
    .dir-locals.el may help
    – shynur
    Commented Dec 27, 2023 at 16:31

1 Answer 1

3

Instead of bothering with using dired-omit-mode to hide dot files, just use the ls switches that give you that behavior (pretty much anything other than switch -a).

And do that only in a particular directory (e.g., your home directory) by using a .dir-locals-file that specifies the specific value of dired-listing-switches that gives you the behavior you want.

(.dir-locals-file is the default value of variable dir-locals-file. See (elisp) Directory Local Variables.)

1
  • So, I have created a file called .dir-locals.el in my home directory, which contains this: ((dired-mode . ((dired-listing-switches . "-lh")))). I am not sure this is correct, however, because it does not hide anything.
    – najjt
    Commented Dec 28, 2023 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.