;;; acdw-shell.el ---Shell config -*- lexical-binding: t; -*- ;;; Code: (defvar eshell-buffer-format "*eshell:%s*" "Format for eshell buffer names.") (defun eshell-rename-pwd () (rename-buffer (format eshell-buffer-format default-directory) t)) (defun eshell-last-dir () (goto-char (point-max)) (insert "cd -") (eshell-send-input)) (defun eshellp (buffer-or-name) (with-current-buffer buffer-or-name (derived-mode-p 'eshell-mode))) (defun +eshell (&optional new) (interactive "P") (let ((dir default-directory) (bname (format eshell-buffer-format default-directory)) (display-comint-buffer-action 'pop-to-buffer)) (if-let ((buf (and (not new) (or (get-buffer bname) (seq-find #'eshellp (reverse (buffer-list))))))) (pop-to-buffer buf) (eshell new)) (eshell-rename-pwd) (unless (equal default-directory dir) (eshell/cd dir) (eshell-send-input) (goto-char (point-max))))) (defun +eshell-quit (&optional choose) (interactive "P") (if choose (let* ((bufs (mapcar #'buffer-name (seq-filter #'eshellp (buffer-list)))) (buf (get-buffer (completing-read "Eshell: " bufs nil t nil nil (car bufs))))) (quit-window) (pop-to-buffer buf)) (quit-window))) (defun acdw/eshell-prompt () "My custom eshell prompt." (concat (if (= 0 eshell-last-command-status) "^_^ " ";_; ") (abbreviate-file-name (eshell/pwd)) (if (= (user-uid) 0) " # " " $ "))) ;;; Packages (use-package eshell :init (add-hook 'eshell-post-command-hook #'eshell-rename-pwd) (setopt eshell-modules-list '(eshell-alias eshell-basic eshell-cmpl eshell-dirs eshell-elecslash eshell-hist eshell-ls eshell-prompt eshell-smart eshell-extpipe eshell-glob eshell-hist eshell-ls eshell-pred eshell-prompt eshell-script eshell-term eshell-unix)) :commands eshell :bind (("C-z" . +eshell) :map eshell-mode-map ("C-z" . +eshell-quit) ("C-o" . eshell-last-dir)) :config (require 'esh-module) (require 'em-smart) (require 'em-tramp) (setopt eshell-destroy-buffer-when-process-dies t eshell-error-if-no-glob t eshell-hist-ignoredups t eshell-kill-on-exit t eshell-prefer-lisp-functions t eshell-prefer-lisp-variables t eshell-scroll-to-bottom-on-input 'this eshell-banner-message "" eshell-hist-ignoredups 'erase eshell-history-size 512 eshell-input-filter (lambda (input) (or (eshell-input-filter-default input) (eshell-input-filter-initial-space input))) eshell-prompt-function #'acdw/eshell-prompt) (add-hook 'eshell-mode-hook (defun eshell-setup () (hungry-delete-mode -1) (setq-local outline-regexp eshell-prompt-regexp page-delimiter eshell-prompt-regexp imenu-generic-expression '(("Prompt" " $ \\(.*\\)" 1)) truncate-lines t) (setenv "PAGER" "cat")))) (use-package eat :ensure t :hook (eshell-load-hook . eat-eshell-mode)) (use-package exec-path-from-shell :when (eq system-type 'gnu/linux) :ensure t :config (add-to-list 'exec-path-from-shell-variables "SSH_AUTH_SOCK") (add-to-list 'exec-path-from-shell-variables "SSH_AGENT_PID") (add-to-list 'exec-path-from-shell-variables "GPG_AGENT_INFO") (add-to-list 'exec-path-from-shell-variables "LANG") (add-to-list 'exec-path-from-shell-variables "LC_CTYPE") (add-to-list 'exec-path-from-shell-variables "XDG_CONFIG_HOME") (add-to-list 'exec-path-from-shell-variables "XDG_CONFIG_DIRS") (add-to-list 'exec-path-from-shell-variables "XDG_DATA_HOME") (add-to-list 'exec-path-from-shell-variables "XDG_DATA_DIRS") (add-to-list 'exec-path-from-shell-variables "XDG_CACHE_HOME") (exec-path-from-shell-initialize)) (use-package eshell-bookmark :ensure t :hook (eshell-mode-hook . eshell-bookmark-setup)) (provide 'acdw-shell) ;;; acdw-shell.el ends here