Switch and manage magit repositories with consult.
consult-magit gives you a single command to jump to a repository,
combining several sources:
- Open Repository — currently open
magit-statusbuffers, with preview. - Repository History — repositories you have previously opened with magit, so you can quickly re-open a local repo even after its buffer has been killed.
- Known Repository (optional) — repositories discovered from
magit-repository-directories. Disabled by default; enable withconsult-magit-include-known-repositories.
While in the minibuffer you can narrow to a single source with consult's
narrowing key (b open buffers, h history, r known repositories).
The package depends on consult and magit.
With use-package and a local checkout:
(use-package consult-magit
:vc (:url "https://github.com/nhojb/consult-magit")
:hook (magit-status-mode . consult-magit-record-repo)
:bind ("C-x C-g" . consult-magit))Or for a local directory (matching a git-package/:git style):
(use-package consult-magit
:load-path "~/Projects/nhojb/emacs/consult-magit"
:hook (magit-status-mode . consult-magit-record-repo)
:bind ("C-x C-g" . consult-magit))The :hook line enables repository history (see below); omit it if you only
want to switch between currently open magit-status buffers.
Repository history is stored in consult-magit-repo-history. To keep it
between Emacs sessions, add it to savehist-additional-variables:
(with-eval-after-load 'savehist
(add-to-list 'savehist-additional-variables 'consult-magit-repo-history))| Variable | Default | Description |
|---|---|---|
consult-magit-history-length |
50 |
Maximum number of repositories kept in the history. |
consult-magit-include-known-repositories |
nil |
When non-nil, offer repositories from magit-repository-directories. |
consult-magit-sources |
see source | The list of consult sources used by consult-magit. |
To build up a history of repositories, add consult-magit-record-repo to
magit-status-mode-hook. Every time a magit-status buffer is created the
repository top-level is then pushed to the front of
consult-magit-repo-history.
The :hook line in the installation examples above does this. Without
use-package add it directly:
(add-hook 'magit-status-mode-hook #'consult-magit-record-repo)Recording is opt-in: if you do not install the hook, consult-magit simply
offers the currently open magit-status buffers.