diff options
Diffstat (limited to 'emacs/site-lisp/my-funcs.el')
| -rw-r--r-- | emacs/site-lisp/my-funcs.el | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/emacs/site-lisp/my-funcs.el b/emacs/site-lisp/my-funcs.el index 8bed290..01bf5cc 100644 --- a/emacs/site-lisp/my-funcs.el +++ b/emacs/site-lisp/my-funcs.el @@ -143,3 +143,16 @@ BEG and END define the region." (defun dired-do-find-marked-files () (interactive) (seq-do 'find-file (dired-get-marked-files))) + +(defun shorten-path (path) + "Shortens each directory in PATH except for the last directory to its first character." + (let* ((components (split-string path "/")) ; Split the path into components + (last-component (-last (lambda (s) (not (string-empty-p s))) components)) ; Extract the last component + (shortened-components ; Shorten all components except the last + (mapcar (lambda (comp) + (if (or (string-equal comp last-component) (string-empty-p comp)) + comp + (substring comp 0 1))) + components))) + (mapconcat 'identity shortened-components "/"))) ; Recombine components into a path + |
