From 0b7c98baf1572458088c431e20d201a421ee042f Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Thu, 10 Dec 2020 21:30:37 -0800 Subject: Add function to eshell config that shortens directory names This function isn't being used yet. --- oni-eshell.el | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'oni-eshell.el') diff --git a/oni-eshell.el b/oni-eshell.el index 71f1e31..16585db 100644 --- a/oni-eshell.el +++ b/oni-eshell.el @@ -4,7 +4,7 @@ ;; Author: Tom Willemse ;; Keywords: local -;; Version: 2020.1106.164034 +;; Version: 2020.1210.213125 ;; Package-Requires: (eshell-fringe-status esh-autosuggest xterm-color eshell-syntax-highlighting) ;; This program is free software; you can redistribute it and/or modify @@ -81,6 +81,24 @@ (eshell/cd (file-name-directory (buffer-file-name (get-buffer buffer-name)))) (eshell-reset)) +(defun oni-eshell-shorten-directories (path) + "Shorten PATH to a list of unique shortened directory names." + (let* ((directories (split-string path "/" t)) + (new-path + (string-join + (mapcar (lambda (d) + (let ((name (substring d 0 1)) + (length 1)) + (while (cl-find-if (lambda (s) (and (not (string= s d)) + (string-prefix-p name s))) + directories) + (setq name (substring d 0 (cl-incf length)))) + name)) + directories) "/"))) + (if (string-prefix-p "~" new-path) + new-path + (concat "/" new-path)))) + (add-hook 'eshell-before-prompt-hook #'oni-eshell--set-xterm-variables) (add-hook 'eshell-first-time-mode-hook #'oni-eshell--expand-keymap) (add-hook 'eshell-load-hook #'oni-eshell--disable-ansi-color-handling) -- cgit v1.2.3-54-g00ecf