From 3ddbe04079ac54d337f41fcb7b1adb7eb7f143d4 Mon Sep 17 00:00:00 2001 From: Tim McCarthy Date: Mon, 16 Sep 2024 13:56:07 -0700 Subject: [PATCH] Move eshell config into its own file --- thoom-emacs/init.el | 1 + thoom-emacs/modules/thoom-eshell.el | 90 +++++++++++++++++++++++++++++ thoom-emacs/modules/thoom-prog.el | 89 ---------------------------- 3 files changed, 91 insertions(+), 89 deletions(-) create mode 100644 thoom-emacs/modules/thoom-eshell.el diff --git a/thoom-emacs/init.el b/thoom-emacs/init.el index c306f12..08bad24 100644 --- a/thoom-emacs/init.el +++ b/thoom-emacs/init.el @@ -26,3 +26,4 @@ (require 'thoom-nix) (require 'thoom-git) (require 'thoom-prog) +(require 'thoom-eshell) diff --git a/thoom-emacs/modules/thoom-eshell.el b/thoom-emacs/modules/thoom-eshell.el new file mode 100644 index 0000000..cbabb7d --- /dev/null +++ b/thoom-emacs/modules/thoom-eshell.el @@ -0,0 +1,90 @@ +(provide 'thoom-eshell) + +(use-package eat + :ensure t + :custom + (eat-term-name "xterm-256color") + :init + (eval-after-load 'eshell #'eat-eshell-mode) + (eval-after-load 'eshell #'eat-eshell-visual-command-mode) + :config + (add-to-list 'eat-semi-char-non-bound-keys (vector meta-prefix-char ?`)) + (add-to-list 'eat-semi-char-non-bound-keys [?\C-o]) + (eat-update-semi-char-mode-map) + + (add-to-list 'eat-eshell-semi-char-non-bound-keys (vector meta-prefix-char ?`)) + (add-to-list 'eat-eshell-semi-char-non-bound-keys [?\C-o]) + (eat-eshell-update-semi-char-mode-map) + + :hook (eat-mode . (lambda () + (setq display-line-numbers nil) + (hl-line-mode -1)))) + +(use-package eshell + :config + (setq eshell-destroy-buffer-when-process-dies t + eshell-visual-commands '()) + + ;; From https://karthinks.com/software/jumping-directories-in-eshell/ + (defun eshell/j (&optional regexp) + "Navigate to a previously visited directory in eshell, or to +any directory proferred by `consult-dir'." + (let ((eshell-dirs (delete-dups + (mapcar 'abbreviate-file-name + (ring-elements eshell-last-dir-ring))))) + (cond + ((and (not regexp) (featurep 'consult-dir)) + (let* ((consult-dir--source-eshell `(:name "Eshell" + :narrow ?e + :category file + :face consult-file + :items ,eshell-dirs)) + (consult-dir-sources (cons consult-dir--source-eshell + consult-dir-sources))) + (eshell/cd (substring-no-properties + (consult-dir--pick "Switch directory: "))))) + (t (eshell/cd (if regexp (eshell-find-previous-directory regexp) + (completing-read "cd: " eshell-dirs)))))))) + +(use-package pcre2el + :ensure t + :config + (defmacro prx (&rest rx-sexp) + "Convert rx-compatible regular expressions to PCRE." + `(rxt-elisp-to-pcre (rx ,@rx-sexp)))) + +(use-package eshell-toggle + :ensure t + :custom + (eshell-toggle-size-fraction 2) + (eshell-toggle-window-side 'below) + :bind (("M-`" . eshell-toggle))) + +(use-package eshell-p10k + :ensure (:host github :repo "elken/eshell-p10k") + :config + (eshell-p10k-def-segment time + "" + (format-time-string "%H:%M" (current-time)) + 'eshell-p10k-distro-face) + + (defun num-exitcode-string () + (if (= eshell-last-command-status 0) + (number-to-string eshell-p10k--prompt-num-index) + (format "%d (%d)" eshell-p10k--prompt-num-index eshell-last-command-status))) + + (defun num-exitcode-face () + (if (= eshell-last-command-status 0) + 'eshell-p10k-git-clean-face + 'eshell-p10k-git-dirty-face)) + + (eshell-p10k-def-segment num-exitcode + "" + (num-exitcode-string) + (num-exitcode-face)) + + (defun eshell-p10k-prompt-function () + "Prompt defining function." + (eshell-p10k-def-prompt '(num-exitcode time dir git))) + (setq eshell-prompt-function #'eshell-p10k-prompt-function + eshell-prompt-regexp eshell-p10k-prompt-string)) diff --git a/thoom-emacs/modules/thoom-prog.el b/thoom-emacs/modules/thoom-prog.el index 1fa9e7a..72fdd0a 100644 --- a/thoom-emacs/modules/thoom-prog.el +++ b/thoom-emacs/modules/thoom-prog.el @@ -35,95 +35,6 @@ (keymap-global-set "C-c o r" #'copy-source-for-reddit) -(use-package eat - :ensure t - :custom - (eat-term-name "xterm-256color") - :init - (eval-after-load 'eshell #'eat-eshell-mode) - (eval-after-load 'eshell #'eat-eshell-visual-command-mode) - :config - (add-to-list 'eat-semi-char-non-bound-keys (vector meta-prefix-char ?`)) - (add-to-list 'eat-semi-char-non-bound-keys [?\C-o]) - (eat-update-semi-char-mode-map) - - (add-to-list 'eat-eshell-semi-char-non-bound-keys (vector meta-prefix-char ?`)) - (add-to-list 'eat-eshell-semi-char-non-bound-keys [?\C-o]) - (eat-eshell-update-semi-char-mode-map) - - :hook (eat-mode . (lambda () - (setq display-line-numbers nil) - (hl-line-mode -1)))) - -(use-package eshell - :config - (setq eshell-destroy-buffer-when-process-dies t - eshell-visual-commands '()) - - ;; From https://karthinks.com/software/jumping-directories-in-eshell/ - (defun eshell/j (&optional regexp) - "Navigate to a previously visited directory in eshell, or to -any directory proferred by `consult-dir'." - (let ((eshell-dirs (delete-dups - (mapcar 'abbreviate-file-name - (ring-elements eshell-last-dir-ring))))) - (cond - ((and (not regexp) (featurep 'consult-dir)) - (let* ((consult-dir--source-eshell `(:name "Eshell" - :narrow ?e - :category file - :face consult-file - :items ,eshell-dirs)) - (consult-dir-sources (cons consult-dir--source-eshell - consult-dir-sources))) - (eshell/cd (substring-no-properties - (consult-dir--pick "Switch directory: "))))) - (t (eshell/cd (if regexp (eshell-find-previous-directory regexp) - (completing-read "cd: " eshell-dirs)))))))) - -(use-package pcre2el - :ensure t - :config - (defmacro prx (&rest rx-sexp) - "Convert rx-compatible regular expressions to PCRE." - `(rxt-elisp-to-pcre (rx ,@rx-sexp)))) - -(use-package eshell-toggle - :ensure t - :custom - (eshell-toggle-size-fraction 2) - (eshell-toggle-window-side 'below) - :bind (("M-`" . eshell-toggle))) - -(use-package eshell-p10k - :ensure (:host github :repo "elken/eshell-p10k") - :config - (eshell-p10k-def-segment time - "" - (format-time-string "%H:%M" (current-time)) - 'eshell-p10k-distro-face) - - (defun num-exitcode-string () - (if (= eshell-last-command-status 0) - (number-to-string eshell-p10k--prompt-num-index) - (format "%d (%d)" eshell-p10k--prompt-num-index eshell-last-command-status))) - - (defun num-exitcode-face () - (if (= eshell-last-command-status 0) - 'eshell-p10k-git-clean-face - 'eshell-p10k-git-dirty-face)) - - (eshell-p10k-def-segment num-exitcode - "" - (num-exitcode-string) - (num-exitcode-face)) - - (defun eshell-p10k-prompt-function () - "Prompt defining function." - (eshell-p10k-def-prompt '(num-exitcode time dir git))) - (setq eshell-prompt-function #'eshell-p10k-prompt-function - eshell-prompt-regexp eshell-p10k-prompt-string)) - (use-package lsp-mode :ensure t :commands lsp