Add project terminal launchers for Emacs

This commit is contained in:
Fabio Scotto di Santolo
2026-04-10 11:03:18 +02:00
parent 895cfb5b10
commit 93b6d8f722
4 changed files with 72 additions and 4 deletions

View File

@@ -83,6 +83,9 @@
(with-eval-after-load 'projectile
(define-key projectile-command-map (kbd "v") #'fscotto/project-vterm)
(define-key projectile-command-map (kbd "V") #'fscotto/project-multi-vterm)
(define-key projectile-command-map (kbd "x") #'fscotto/project-external-terminal)
(define-key projectile-command-map (kbd "a") #'fscotto/project-opencode)
(define-key projectile-command-map (kbd "g") #'fscotto/project-magit-status))
;;;; LSP

View File

@@ -23,6 +23,42 @@
(let ((default-directory (fscotto/project-root)))
(vterm)))
(defun fscotto/project-multi-vterm ()
"Open a new multi-vterm buffer in project root."
(interactive)
(let ((default-directory (fscotto/project-root)))
(multi-vterm)))
(defun fscotto/launch-external-terminal (&optional command)
"Launch external terminal in project root, optionally running COMMAND."
(let* ((default-directory (file-name-as-directory (fscotto/project-root)))
(terminal-program (or (executable-find fscotto/external-terminal-program)
fscotto/external-terminal-program))
(args (append
(list fscotto/external-terminal-working-directory-option
default-directory)
(when command
(append
(list fscotto/external-terminal-execute-option)
command)))))
(unless (file-executable-p terminal-program)
(user-error "External terminal not found: %s" fscotto/external-terminal-program))
(apply #'start-process
"fscotto-external-terminal"
nil
terminal-program
args)))
(defun fscotto/project-external-terminal ()
"Open the external terminal in project root."
(interactive)
(fscotto/launch-external-terminal))
(defun fscotto/project-opencode ()
"Open the external terminal in project root and run opencode."
(interactive)
(fscotto/launch-external-terminal '("opencode")))
(defun fscotto/project-magit-status ()
"Open magit-status in project root."
(interactive)

View File

@@ -1,4 +1,32 @@
;;; terminal.el -*-
;;; terminal.el -*- lexical-binding: t; -*-
(defgroup fscotto nil
"Personal customization group."
:group 'applications)
(defcustom fscotto/external-terminal-program "alacritty"
"Program used to launch external terminal windows."
:type 'string
:group 'fscotto)
(defcustom fscotto/external-terminal-working-directory-option "--working-directory"
"Argument used to set the working directory for the external terminal."
:type 'string
:group 'fscotto)
(defcustom fscotto/external-terminal-execute-option "-e"
"Argument used to execute a command in the external terminal."
:type 'string
:group 'fscotto)
(use-package vterm
:ensure t)
(use-package multi-vterm
:ensure t
:after vterm
:commands (multi-vterm multi-vterm-next multi-vterm-prev))
(provide 'terminal)
;;; terminal.el ends here

View File

@@ -141,13 +141,14 @@
;; Actions
"C-c p c" "Compile"
"C-c p t" "Test"
"C-c p v" "Open term in project"
"C-c p v" "Open vterm in project"
"C-c p V" "Open multi-vterm in project"
"C-c p x" "Open external term"
"C-c p a" "Open opencode"
"C-c p e" "Edit project config"
"C-c p g" "Project Git status"
"C-c p x" "Open Terminal"
"C-c p 4" "Other Window"
"C-c p 5" "Other Frame"
"C-c p x 4" "Other Window"
;; Cache
"C-c p i" "Invalidate cache")