From 99433f640aa628e3f5ada562edbd5b61fe062448 Mon Sep 17 00:00:00 2001 From: Nicholas Rodrigues Lordello Date: Fri, 31 Oct 2025 17:22:00 +0100 Subject: Magit and Devbox I typically develop in isolated developer containers/vms; this changes the standard `C-x g` binding that opens the Magit status to instead try and open the local git repository for a TRAMP remote file. This makes it so I do Git things locally (including signing git commits) but can still develop in an isolated `devbox` environment, without having to share my GPG or SSH credentials. --- config/emacs/init.el | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/config/emacs/init.el b/config/emacs/init.el index add3676..1d183ac 100644 --- a/config/emacs/init.el +++ b/config/emacs/init.el @@ -75,6 +75,18 @@ (when is-dir (project-remember-projects-under name))))) +(defun devbox/magit-status () + "Opens the local Git status for a devbox directory. + +If the current buffer is not open in the devbox, then this function just runs +`magit-status' normally." + (interactive) + (if (equal (file-remote-p default-directory 'host) "devbox") + (let ((local-dir (tramp-file-name-localname + (tramp-dissect-file-name default-directory)))) + (magit-status-setup-buffer local-dir)) + (magit-status))) + ;;; -- Emacs Configuration -- (use-package emacs @@ -184,7 +196,7 @@ (use-package magit :ensure t - :bind (("C-x g" . magit-status))) + :bind (("C-x g" . devbox/magit-status))) (use-package undo-tree :ensure t @@ -205,8 +217,8 @@ (when (init/dev) (use-package copilot :ensure t - :bind (("C-" . copilot-accept-completion) - ("C-M-" . copilot-accept-completion-by-word) + :bind (("M-" . copilot-accept-completion) + ("C-" . copilot-accept-completion-by-word) ("C-c a a" . copilot-mode) ("C-c a n" . copilot-next-completion) ("C-c a p" . copilot-previous-completion)))) -- cgit v1.2.3