;;; shell.el -*- lexical-binding: t; -*- ;;; ;;; Author: Jakob L. Kreuze ;;; URL: https://git.sr.ht/~jakob/.emacs.d/ ;;; ;;; `shell' is sometimes clunky, and I can't get `alacritty' to work on my ;;; Pinebook Pro anymore, so I've been experimenting with `vterm'. Thus far, it ;;; is a nice medium between the two, so I am considering dropping `shell' ;;; altogether, albeit with a very slow transition-out. ;;; ;; Global variable that we use for the custom modeline. (defvar vterm-buffer-titles (make-hash-table) "Title set by shell program.") ;; Some niceties for creating VTerm buffers with descriptive names. (defun vterm-create-session-interactively (&optional ARG) "Wrapper around `vterm' to _always_ create a new session. Possibly with a user-specified distinctive name." (interactive "p") (if (/= ARG 1) (vterm (format "*vterm*<%s>" (read-string "Name of buffer: "))) (vterm 't))) (defun vterm-cycle-buffers () "Switch to a vterm buffer in a cyclic order. If a vterm buffer is currently open, choose the next in the ring. Otherwise, switch to the first available vterm buffer." (interactive) (let* ((buffer-names (mapcar #'buffer-name (buffer-list))) (candidates (seq-filter (lambda (x) (string-search "*vterm*" x)) buffer-names)) (cur-idx (or (cl-position-if (lambda (x) (string= x (buffer-name (current-buffer)))) candidates) -1)) (idx (if (= (1+ cur-idx) (length candidates)) 0 (1+ cur-idx)))) (switch-to-buffer (elt candidates idx)))) (use-package vterm ;; Hook into `vterm--set-title' for updating our custom modeline. :config (defun vterm--set-title (title) "Use TITLE to set the buffer name according to `vterm-buffer-name-string'." (puthash (current-buffer) title vterm-buffer-titles)) ;; Custom keybindings for cycling through open VTerm buffers. :bind (:map vterm-mode-map ("M-s-p" . vterm-cycle-buffers)) :bind ("s-" . (lambda () (interactive) (vterm-create-session-interactively 2))))