From b099c779343119ce40f2636469e118ec104002e0 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 10 May 2026 03:25:35 -0500 Subject: refactor: split eshell-vterm-config into eshell-config and vterm-config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The combined module had grown to 573 lines covering two unrelated subsystems with no shared state — the eshell shell-mode commands and the vterm/F12 toggle. The header even rendered this with two `;; ----` dividers. Split into two focused modules. eshell-config.el keeps the eshell user commands and package wiring (~170 lines). vterm-config.el keeps the vterm package, the tmux history capture command, the F12 toggle, and the C-; V keymap (~400 lines). Update init.el to require both, point the four vterm test files at vterm-config, and refresh the cross-module commentary in cj-window-geometry.el and cj-window-toggle.el. No behavior change. Full test suite green; validate-modules clean. --- modules/eshell-config.el | 174 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 modules/eshell-config.el (limited to 'modules/eshell-config.el') diff --git a/modules/eshell-config.el b/modules/eshell-config.el new file mode 100644 index 00000000..62b3a7ab --- /dev/null +++ b/modules/eshell-config.el @@ -0,0 +1,174 @@ +;;; eshell-config.el --- Settings for the Emacs Shell -*- lexical-binding: t; coding: utf-8; -*- +;; author Craig Jennings + +;;; Commentary: + +;; ESHELL +;; - Eshell is useful as a REPL +;; - Redirect to the kill ring : ls > /dev/kill +;; - Redirect to the clioboard : ls > /dev/clip +;; - Redirect to a buffer : ls > # +;; - Use elisp functions : write your own "detox" command in elisp +;; : then use it in eshell +;; - cd to remote directories : cd /sshx:c@cjennings.net:/home/cjennings +;; : and take all the elisp functionality remotely +;; : including Dired or Magit on a remote server + +;;; Code: + +(require 'system-utils) + +(use-package eshell + :ensure nil ;; built-in + :commands (eshell) + :config + (setq eshell-banner-message "") + (setq eshell-scroll-to-bottom-on-input 'all) + (setq eshell-error-if-no-glob t) + (setq eshell-hist-ignoredups t) + (setq eshell-save-history-on-exit t) + (setq eshell-prefer-lisp-functions nil) + (setq eshell-destroy-buffer-when-process-dies t) + + ;; no pagers required + (setenv "PAGER" "cat") + + (setq eshell-prompt-function + (lambda () + (concat + (propertize (format-time-string "[%d-%m-%y %T]") 'face '(:foreground "gray")) + " " + (propertize (user-login-name) 'face '(:foreground "gray")) + " " + (propertize (system-name) 'face '(:foreground "gray")) + ":" + (propertize (abbreviate-file-name (eshell/pwd)) 'face '(:foreground "gray")) + "\n" + (propertize "%" 'face '(:foreground "white")) + " "))) + + (add-hook + 'eshell-mode-hook + (lambda () + (setq pcomplete-cycle-completions nil))) + (setq eshell-cmpl-cycle-completions nil) + + (add-to-list 'eshell-modules-list 'eshell-tramp) + + (add-hook 'eshell-hist-mode-hook + (lambda () + (keymap-set eshell-hist-mode-map "" #'previous-line) + (keymap-set eshell-hist-mode-map "" #'next-line))) + + (add-hook 'eshell-mode-hook + (lambda () + (add-to-list 'eshell-visual-commands '("lf" "ranger" "tail" "htop" "gotop" "mc" "ncdu" "top")) + (add-to-list 'eshell-visual-subcommands '("git" "log" "diff" "show")) + (add-to-list 'eshell-visual-options '("git" "--help" "--paginate")) + + ;; aliases + (eshell/alias "e" "find-file $1") + (eshell/alias "em" "find-file $1") + (eshell/alias "emacs" "find-file $1") + (eshell/alias "open" "cj/xdg-open $1") + (eshell/alias "gocj" "cd /sshx:cjennings@cjennings.net:/var/cjennings/") + (eshell/alias "gosb" "cd /sshx:cjennings@wolf.usbx.me:/home/cjennings/") + (eshell/alias "gowolf" "cd /sshx:cjennings@wolf.usbx.me:/home/cjennings/") + (eshell/alias "v" "eshell-exec-visual $*") + (eshell/alias "ff" "find-file-other-window $1") + (eshell/alias "f" "find-using-dired $1") + (eshell/alias "r" "ranger") + (eshell/alias "ll" "ls -laF")))) + +(defun eshell/find-file-other-window (&rest files) + "Open FILE(s) in other window from eshell." + (if (= 1 (length files)) + ;; Single file - just use it directly + (find-file-other-window (car files)) + ;; Multiple files - open each in other window + (dolist (file files) + (find-file-other-window file)))) + +(defun eshell/find-file (&rest files) + "Open FILE(s) from eshell." + (if (= 1 (length files)) + ;; Single file + (find-file (car files)) + ;; Multiple files + (dolist (file files) + (find-file file)))) + +(defun eshell/clear () + "Clear the eshell buffer." + (let ((inhibit-read-only t)) + (erase-buffer) + (eshell-send-input))) + +(defun eshell/find-using-dired (file-pattern) + "Find a file matching FILE-PATTERN using `find-name-dired'." + (let ((escaped-pattern (regexp-quote file-pattern))) + (find-name-dired default-directory escaped-pattern))) + +(defun cj/eshell-delete-window-on-exit () + "Close the eshell window when exiting." + (when (not (one-window-p)) + (delete-window))) +(advice-add 'eshell-life-is-too-much :after 'cj/eshell-delete-window-on-exit) + +(use-package eshell-toggle + :custom + (eshell-toggle-size-fraction 2) + (eshell-toggle-run-command nil) + (eshell-toggle-init-function #'eshell-toggle-init-eshell) + :bind + ("C-" . eshell-toggle)) + +(use-package xterm-color + :after eshell + :hook + (eshell-before-prompt-hook . (lambda () + (setq xterm-color-preserve-properties t))) + :config + (setenv "TERM" "xterm-256color")) + +(use-package eshell-syntax-highlighting + :after esh-mode + :config + (eshell-syntax-highlighting-global-mode +1)) + +(use-package eshell-up + :after eshell + :config + (defalias 'eshell/up 'eshell-up) + (defalias 'eshell/up-peek 'eshell-up-peek)) + +;; Enhance history searching +(defun cj/eshell-history-search () + "Search eshell history with completion." + (interactive) + (insert + (completing-read "Eshell history: " + (delete-dups + (ring-elements eshell-history-ring))))) + +(add-hook 'eshell-mode-hook + (lambda () + (keymap-set eshell-mode-map "C-r" #'cj/eshell-history-search))) + +;; Better completion for eshell +(use-package pcmpl-args + :after eshell) + +;; Company mode integration for eshell +(use-package company-shell + :after (eshell company) + :config + (add-to-list 'company-backends 'company-shell) + (add-hook 'eshell-mode-hook + (lambda () + (setq-local company-minimum-prefix-length 2) + (setq-local company-idle-delay 2) + (company-mode 1)))) + +(provide 'eshell-config) +;;; eshell-config.el ends here. -- cgit v1.2.3