summary refs log tree commit diff
path: root/emacs/custom
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2021-10-17 13:36:14 -0700
committerFranck Cuny <franck@fcuny.net>2021-10-17 13:36:14 -0700
commit67afdf76cdcc212ffe2234a044092c7ce367936f (patch)
tree93526a0a0727ebe5d69c7ec8a39c044fa02cb702 /emacs/custom
parentaspell: words (diff)
downloademacs.d-67afdf76cdcc212ffe2234a044092c7ce367936f.tar.gz
emacs: custom prompt for eshell
Diffstat (limited to 'emacs/custom')
-rw-r--r--emacs/custom/fcuny-eshell.el33
1 files changed, 33 insertions, 0 deletions
diff --git a/emacs/custom/fcuny-eshell.el b/emacs/custom/fcuny-eshell.el
index a3cf178..1e0d994 100644
--- a/emacs/custom/fcuny-eshell.el
+++ b/emacs/custom/fcuny-eshell.el
@@ -50,6 +50,38 @@
   (magit-status (pop args) nil)
   (eshell/echo))   ;; The echo command suppresses output
 
+(defun fcuny/shorten-path (path &optional max-len)
+  "Return a potentially trimmed-down version of the directory PATH, replacing
+parent directories with their initial characters to try to get the character
+length of PATH (sans directory slashes) down to MAX-LEN."
+  (let* ((components (split-string (abbreviate-file-name path) "/"))
+         (max-len (or max-len 30))
+         (len (+ (1- (length components))
+                 (cl-reduce '+ components :key 'length)))
+         (str ""))
+    (while (and (> len max-len)
+                (cdr components))
+      (setq str (concat str
+                        (cond ((= 0 (length (car components))) "/")
+                              ((= 1 (length (car components)))
+                               (concat (car components) "/"))
+                              (t
+                               (if (string= "."
+                                            (string (elt (car components) 0)))
+                                   (concat (substring (car components) 0 2)
+                                           "/")
+                                 (string (elt (car components) 0) ?/)))))
+            len (- len (1- (length (car components))))
+            components (cdr components)))
+    (concat str (cl-reduce (lambda (a b) (concat a "/" b)) components))))
+
+(defun fcuny/eshell-prompt ()
+  (setq eshell-prompt-regexp "; ")
+  (concat
+   (concat (system-name) ":")
+   (fcuny/shorten-path (eshell/pwd))
+   "; "))
+
 (defun fcuny/eshell-here ()
   "Opens up a new shell in the directory associated with the current
 buffer's file. The eshell is renamed to match that directory to make
@@ -135,6 +167,7 @@ append to it, while separating multiple outputs with
   (eshell-where-to-jump 'begin)
   (eshell-review-quick-commands nil)
   (eshell-smart-space-goes-to-end t)
+  (eshell-prompt-function 'fcuny/eshell-prompt)
   (eshell-destroy-buffer-when-process-dies t))
 
 (use-package eshell-bookmark