add gitswitch and git repo list to consult-buffer, do: g SPC

This commit is contained in:
2026-07-30 23:59:55 +02:00
parent 586caeffba
commit f94826d8cc
4 changed files with 58 additions and 11 deletions

5
.gitignore vendored
View File

@@ -24,3 +24,8 @@ emms
macros.el
forge-database.sqlite
forge-database*
.cache
cache
*history*
tree-sitter
warnings

View File

@@ -138,9 +138,9 @@
:custom-face
(blamer-face ((t :foreground "#7a88cf"
:background nil
:height 140
:italic t)))
:background nil
:height 140
:italic t)))
:config
(defalias 'blame 'blamer-mode)
@@ -148,10 +148,10 @@
;; in addition to blaming I also like to follow the lead, so make
;; the hash lead to the commit by clicking on it.
(defun blamer-callback-show-commit-diff (commit-info)
(interactive)
(let ((commit-hash (plist-get commit-info :commit-hash)))
(when commit-hash
(magit-show-commit commit-hash))))
(interactive)
(let ((commit-hash (plist-get commit-info :commit-hash)))
(when commit-hash
(magit-show-commit commit-hash))))
(setq blamer-bindings '(("<mouse-1>" . blamer-callback-show-commit-diff))))
@@ -161,5 +161,34 @@
(use-package sqlite3
:defer nil)
;; git helpers
(defun tvd-list-git-repos()
"Returns a list of all available git repositories in dev and fits/git"
(interactive)
(setq repos (list))
(let ((bases (list "~/dev" "~/fits/git")))
(dolist (base bases)
(dolist (dir (directory-files base nil "^[^\\.]"))
(if (and (file-accessible-directory-p (concat base "/" dir "/.git"))
(not (s-suffix? "bak" dir) ))
(push dir repos)))))
repos)
(defun tvd-switch-to-repo(repo)
"calls magit-status with <repo>, switches to and changes dir to it"
(interactive)
(let* ((devdir (concat "~/dev/" repo))
(fitsdir (concat "~/fits/git/" repo)))
(cond
((file-accessible-directory-p (concat devdir "/.git"))
(magit-status devdir))
((file-accessible-directory-p (concat fitsdir "/.git"))
(magit-status fitsdir)))))
(defun gitswitch()
"select a git repo from a list and switch to it"
(interactive)
(tvd-switch-to-repo (completing-read "select git repo> " (tvd-list-git-repos))))
(provide 'init-magit)
;;; init-magit.el ends here

View File

@@ -212,7 +212,6 @@ targets."
(consult-widen-key ">")
:config
(when (fboundp 'persp-new)
(consult-customize consult--source-buffer :hidden t :default nil)
@@ -224,7 +223,21 @@ targets."
:default t
:items #'persp-get-buffer-names))
(push consult--source-perspective consult-buffer-sources)))
(push consult--source-perspective consult-buffer-sources))
(defvar git-source
(list :name "Git Repo"
:category 'consult-location
:narrow ?g
:face 'consult-buffer
:history 'buffer-name-history
:state #'consult--buffer-state
:sort t
:action #'tvd-switch-to-repo
:items #'tvd-list-git-repos))
(add-to-list 'consult-buffer-sources 'git-source 'append))
;; needs to be defined outside
(defalias 'rg 'consult-ripgrep)
@@ -273,7 +286,7 @@ targets."
([backtab] . corfu-previous)))
;; much better experience to seach current buffer consult-line would
;; much better experience to seach current buffer, consult-line would
;; do the job as well and looks similar, but I'm used to swiper, so
;; stick with it.
(use-package swiper

View File

@@ -146,7 +146,7 @@ _k_: kill (C-k) _s_: split _{_: wrap with { }
(define-key smartparens-mode-map (kbd "C-x (") 'hydra-smartparens/body))
:bind (:map smartparens-mode-map
:bind (;:map smartparens-mode-map
;; auto wrapping w/o region
( "C-c (" . 'wrap-with-parens)
( "C-c [" . 'wrap-with-brackets)