10

I often have many dired buffers open, including some for folders that have identical names. Occasionally, this causes me to switch to the wrong one, so I am looking for a way to fix this.

Currently, if I have multiple identically-named folders open in dired, then my buffer list looks something like this:

foo
foo<2>
bar
foo<3>
bar<2>

I would like to include the full path (or some portion of it) in the buffer name so I can see which folder I am actually switching to. I would prefer to do it like this:

foo</full/path/to/foo>
foo</another/path>

and so on. I could also settle for e.g.:

/full/path/to/foo
/another/path/foo

but I would prefer the former, because it will usually be easier to find the buffer I want by folder name first, and full path second. How can this be done?

Scott Weldon
  • 2,695
  • 1
  • 17
  • 31

2 Answers2

8

You can get this behavior by using uniquify with the following settings:

(require 'uniquify)
(setq uniquify-buffer-name-style 'post-forward-angle-brackets
      uniquify-min-dir-content 999)

Note however that uniquify works globally, not only on dired buffers.

Chillar Anand
  • 4,042
  • 1
  • 23
  • 52
paprika
  • 1,944
  • 19
  • 26
  • Cool, thanks! I will wait and see if there is a solution that does give a full path before I accept an answer. – Scott Weldon Oct 14 '14 at 00:03
  • 1
    I just added a note about `uniquify-min-dir-content`, which should help you with that. Note however, that this is a global setting: it applies to all buffers, not just dired buffers! – paprika Oct 14 '14 at 00:06
6

In my .emacs I set full paths for Dired buffers this way:

(add-hook 'dired-after-readin-hook
      (lambda ()
        ;; Set name of dired buffers to absolute directory name.
        ;; Use `generate-new-buffer-name' for vc-directory
        ;; which creates duplicate buffers.
        (rename-buffer (generate-new-buffer-name dired-directory))))
link0ff
  • 1,081
  • 5
  • 14
  • 1
    One advantage of this: you can customize how you name dired buffers, such as with a "dired: " prefix or something – Amory Mar 18 '21 at 11:44