[Emacs] Rename eshell/my-prompt', simplify
phundrak/abbr-pwd'
This commit renames `eshell/my-prompt' to `phundrak/eshell-prompt'. `phundrak/abbr-pwd' is now simplified, and it is no longer responsible for fetching the current path which must now be passed as its first argument. It will also reject any argument which is neither a string (should be the only type to be passed for public use) nor a list (for internal usage).
This commit is contained in:
parent
a405eb602a
commit
72496186f5
@ -1404,22 +1404,22 @@
|
|||||||
path, but leaves the current one written in full. It also abbreviates the
|
path, but leaves the current one written in full. It also abbreviates the
|
||||||
equivalent of the ~$HOME~ (~/home/<username>/~) directory to a simple =~=.
|
equivalent of the ~$HOME~ (~/home/<username>/~) directory to a simple =~=.
|
||||||
#+BEGIN_SRC emacs-lisp
|
#+BEGIN_SRC emacs-lisp
|
||||||
(defun phundrak/abbr-pwd (&optional $abbreviate $path $abbreviating)
|
(defun phundrak/abbr-pwd ($path &optional $abbreviate)
|
||||||
(cond
|
(cond
|
||||||
((and (null $path)
|
((stringp $path) (f-short
|
||||||
$abbreviating) "")
|
(if $abbreviate
|
||||||
((and $abbreviate
|
(phundrak/abbr-pwd (f-split (abbr-pwd $path)))
|
||||||
(= 1 (length $path)))
|
$path)))
|
||||||
(car $path))
|
((null $path) "")
|
||||||
((and $abbreviate $path)
|
((listp $path)
|
||||||
(f-join (let* ((dir (car $path))
|
(f-join (cond ((= 1 (length $path)) (car $path))
|
||||||
|
(t (let* ((dir (car $path))
|
||||||
(first-char (s-left 1 dir)))
|
(first-char (s-left 1 dir)))
|
||||||
(if (string= "." first-char)
|
(if (string= "." first-char)
|
||||||
(s-left 2 dir)
|
(s-left 2 dir)
|
||||||
first-char))
|
first-char))))
|
||||||
(phundrak/abbr-pwd t (cdr $path) t)))
|
(phundrak/abbr-pwd (cdr $path))))
|
||||||
($abbreviate (f-short (phundrak/abbr-pwd t (f-split (phundrak/abbr-pwd)))))
|
(t (error "Invalid argument %s, neither stringp nor listp" $path))))
|
||||||
(t (f-short (eshell/pwd)))))
|
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
*** ~phundrak/prompt-toggle-abbreviation~
|
*** ~phundrak/prompt-toggle-abbreviation~
|
||||||
@ -1965,7 +1965,7 @@
|
|||||||
is ~t~ it is abbreviated; otherwise, it is kept in full. It can be toggled
|
is ~t~ it is abbreviated; otherwise, it is kept in full. It can be toggled
|
||||||
with a keyboard shortcut, see [[#User_Configuration-Shortcuts-Toggle-d53c27ef][Keybindings: Toggle]].
|
with a keyboard shortcut, see [[#User_Configuration-Shortcuts-Toggle-d53c27ef][Keybindings: Toggle]].
|
||||||
#+BEGIN_SRC emacs-lisp
|
#+BEGIN_SRC emacs-lisp
|
||||||
(defun eshell/my-prompt ()
|
(defun phundrak/eshell-prompt ()
|
||||||
"Definition of my prompt for Eshell
|
"Definition of my prompt for Eshell
|
||||||
|
|
||||||
It displays a powerline prompt, with first an abbreviated path to
|
It displays a powerline prompt, with first an abbreviated path to
|
||||||
@ -1983,8 +1983,8 @@
|
|||||||
red depending on if the last eshell command was a success or a
|
red depending on if the last eshell command was a success or a
|
||||||
failure respectively."
|
failure respectively."
|
||||||
(let* ((header-bg phundrak/nord0)
|
(let* ((header-bg phundrak/nord0)
|
||||||
($path (phundrak/abbr-pwd))
|
($path (phundrak/abbr-pwd (eshell/pwd)))
|
||||||
($abbr-path (phundrak/abbr-pwd phundrak/prompt--abbreviate))
|
($abbr-path (phundrak/abbr-pwd $path phundrak/prompt--abbreviate))
|
||||||
($background phundrak/nord1))
|
($background phundrak/nord1))
|
||||||
(concat (with-face " " :background $background)
|
(concat (with-face " " :background $background)
|
||||||
(with-face $abbr-path
|
(with-face $abbr-path
|
||||||
@ -2008,7 +2008,7 @@
|
|||||||
Now, let’s declare our prompt regexp and our prompt functions:
|
Now, let’s declare our prompt regexp and our prompt functions:
|
||||||
#+BEGIN_SRC emacs-lisp
|
#+BEGIN_SRC emacs-lisp
|
||||||
(setq eshell-prompt-regexp "^[^#$\n]*[#$] "
|
(setq eshell-prompt-regexp "^[^#$\n]*[#$] "
|
||||||
eshell-prompt-function 'eshell/my-prompt)
|
eshell-prompt-function 'phundrak/eshell-prompt)
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
*** Org-mode
|
*** Org-mode
|
||||||
|
Loading…
Reference in New Issue
Block a user