I'm moving to emacs from shell/Vim and I'm very used to seeing the branch I'm working in when I'm at the project level. Is there any way to get the Git branch name to display in the dired buffer mode line for my projects?
1 Answer
No it doesn't. Maybe dired-k can do it, or some other Git related package.
But neither Magit nor VC show this information in Dired buffers. By the way, while Magit uses its own code to update the information displayed in the mode-line of file-visiting buffers, it does so by updating the variable vc-display-status
the same way VC would. VC's implementation does many other costly things in its respective function, and because Magit updates the mode-line much more often, it needed an optimized implementation.
If you want to implement this yourself, then look at the linked function and then adapt it for Dired buffers. Then you would have to loop over all buffers to find Dired buffers (similar to what is being done in magit-revert-buffers
but much less complicated). Finally to hook this into Magit advice magit-revert-buffers
to call your function. (I can also add a hook for that, but only once there actually exists code that could use that.)
-
-
@tarsius is there other way to do it using modern Magit? I tried get this information via
(magit-get-current-branch)
but this throws on buffers like scratch.– NavidotFeb 4, 2021 at 15:51 -
Magit still doesn't do this and I don't plan to add it. Before using a function that has to be run inside a repository, make sure you actually are inside a repository (as per
default-directory
).– tarsiusFeb 4, 2021 at 17:09