From fdc973159d1f25db3726f64b583626a6e5cfd0f1 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Tue, 12 Nov 2019 09:14:50 +0100 Subject: [PATCH] Eshell: Replace custom prompt with eshell-prompt-extras package. --- .emacs.d/lisp/init-eshell.el | 67 +++++------------------------------- 1 file changed, 9 insertions(+), 58 deletions(-) diff --git a/.emacs.d/lisp/init-eshell.el b/.emacs.d/lisp/init-eshell.el index 03d0295f..00d91a65 100644 --- a/.emacs.d/lisp/init-eshell.el +++ b/.emacs.d/lisp/init-eshell.el @@ -111,42 +111,6 @@ eshell-hist-ignoredups t eshell-destroy-buffer-when-process-dies t) -(defun ambrevar/eshell-prompt () - (let ((path (abbreviate-file-name (eshell/pwd)))) - (concat - (when ambrevar/eshell-status-p - (propertize (or (ambrevar/eshell-status-display) "") 'face font-lock-comment-face)) - (format - (propertize "(%s@%s)" 'face '(:weight bold)) - (propertize (user-login-name) 'face '(:foreground "cyan")) - (propertize (system-name) 'face '(:foreground "cyan"))) - (if (and (require 'magit nil t) (or (magit-get-current-branch) (magit-get-current-tag))) - ;; We need "--show-prefix and not "--top-level" when we don't follow symlinks. - (let* ((git-file-path (abbreviate-file-name (magit-rev-parse "--show-prefix"))) - prefix) - (let ((common-folder (car (split-string git-file-path "/")))) - (setq prefix (mapconcat 'identity (seq-take-while - (lambda (s) (not (string= s common-folder))) - (split-string path "/")) - "/"))) - (format - (propertize "[%s/%s@%s]" 'face '(:weight bold)) - (propertize prefix 'face `(:foreground ,(if (= (user-uid) 0) "red" "green") :weight bold)) - (propertize (substring-no-properties path (min (length path) (1+ (length prefix)))) - 'face `(:foreground ,(if (= (user-uid) 0) "orange" "gold"))) - (or (magit-get-current-branch) (magit-get-current-tag)))) - (format - (propertize "[%s]" 'face '(:weight bold)) - (propertize path 'face `(:foreground ,(if (= (user-uid) 0) "red" "green") :weight bold)))) - (propertize "\n>" 'face '(:weight bold)) - " "))) - -;;; Leave `eshell-highlight-prompt' to t as it sets the read-only property. -(setq eshell-prompt-function #'ambrevar/eshell-prompt) -;;; If the prompt spans over multiple lines, the regexp should match -;;; last line only. -(setq-default eshell-prompt-regexp "^> ") - (with-eval-after-load 'em-term (dolist (p '("abook" "alsamixer" "cmus" "fzf" "gtypist" "htop" "mpsyt" "mpv" "mutt" "ncdu" "newsbeuter" "pinentry-curses" "ranger" "watch" "wifi-menu")) (add-to-list 'eshell-visual-commands p)) @@ -280,30 +244,9 @@ This should be faster then `seq-uniq'." (add-hook 'eshell-mode-hook 'esh-autosuggest-mode) (define-key esh-autosuggest-active-map (kbd "") 'company-complete-selection) (when (require 'helm-config nil t) + ;; TODO: Why is this in esh-autosuggest? Move to toplevel. (define-key company-active-map (kbd "M-p") 'helm-eshell-history))) -;;; Extra execution information -(defvar ambrevar/eshell-status-p t - "If non-nil, display status before prompt.") -(defvar ambrevar/eshell-status--last-command-time nil) -(make-variable-buffer-local 'ambrevar/eshell-status--last-command-time) -(defvar ambrevar/eshell-status-min-duration-before-display 1 - "If a command takes more time than this, display its duration.") - -(defun ambrevar/eshell-status-display () - (when ambrevar/eshell-status--last-command-time - (let ((duration (time-subtract (current-time) ambrevar/eshell-status--last-command-time))) - (setq ambrevar/eshell-status--last-command-time nil) - (when (> (time-to-seconds duration) ambrevar/eshell-status-min-duration-before-display) - (format "#[STATUS] End time %s, duration %.3fs\n" - (format-time-string "%F %T" (current-time)) - (time-to-seconds duration)))))) - -(defun ambrevar/eshell-status-record () - (setq ambrevar/eshell-status--last-command-time (current-time))) - -(add-hook 'eshell-pre-command-hook 'ambrevar/eshell-status-record) - ;;; Detach (when (require 'package-eshell-detach nil t) (defun ambrevar/eshell-detach-set-keys () @@ -346,4 +289,12 @@ This should be faster then `seq-uniq'." (ignore-errors (cycle-spacing 0)) (insert string)))) +;; (when (require 'eshell-did-you-mean nil 'noerror) +;; (eshell-did-you-mean-setup)) + +(when (require 'eshell-prompt-extras nil 'noerror) + ;; Leave `eshell-highlight-prompt' to t as it sets the read-only property. + (setq epe-path-style 'full) + (setq eshell-prompt-function #'epe-theme-multiline-with-status)) + (provide 'init-eshell)