All ability to set icon face to eshell-starship.el

This commit is contained in:
Alexander Rosenberg 2024-12-22 00:16:15 -08:00
parent f81f0c6a15
commit b6ddcd03c0
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730
2 changed files with 71 additions and 33 deletions

View File

@ -58,6 +58,12 @@ appear at most once to denote \"all remaining modules\"."
:tag "Suppress eshell-starship explore refresh messages" :tag "Suppress eshell-starship explore refresh messages"
:type 'boolean) :type 'boolean)
(defface eshell-starship-icon-face '((t :inherit default))
"Face to use when drawing module icons.
Note that the foreground color will be overridden by the module."
:group 'eshell-starship
:tag "Icon face")
;;; Module API ;;; Module API
(defvar eshell-starship-modules (make-hash-table :test 'equal) (defvar eshell-starship-modules (make-hash-table :test 'equal)
@ -252,7 +258,7 @@ Example:
:doc "The current working directory.") :doc "The current working directory.")
;;; VC (git) module ;;; Git module
(defun eshell-starship--git-parse-status-headers () (defun eshell-starship--git-parse-status-headers ()
"Parse the status headers (read from the current buffer). "Parse the status headers (read from the current buffer).
The headers are as described in the porcelain v2 section of the git-status(3) The headers are as described in the porcelain v2 section of the git-status(3)
@ -372,14 +378,15 @@ For example, a revert. If there is no current operation, return nil."
(goto-char (point-min)) (goto-char (point-min))
(cl-destructuring-bind (oid head _upstream ahead behind stash) (cl-destructuring-bind (oid head _upstream ahead behind stash)
(eshell-starship--git-parse-status-headers) (eshell-starship--git-parse-status-headers)
(let ((file-status (eshell-starship--git-file-status stash ahead (let* ((file-status (eshell-starship--git-file-status stash ahead
behind)) behind))
(operation (eshell-starship--git-current-operation))) (operation (eshell-starship--git-current-operation))
(output
(concat (concat
(if (string= "(detached)" head) (if (string= "(detached)" head)
(propertize (concat " (" (substring oid 0 7) ")") (propertize (concat " (" (substring oid 0 7) ")")
'face '(:foreground "lawn green")) 'face '(:foreground "lawn green"))
(propertize (concat "󰊢 " head) (propertize (concat head)
'face '(:foreground "medium purple"))) 'face '(:foreground "medium purple")))
(unless (string-empty-p file-status) (unless (string-empty-p file-status)
(propertize (concat " [" file-status "]") (propertize (concat " [" file-status "]")
@ -387,24 +394,35 @@ For example, a revert. If there is no current operation, return nil."
(when operation (when operation
(concat " (" (propertize (concat " (" (propertize
operation 'face operation 'face
'(:inherit bold :foreground "yellow")) ")")))))))) '(:inherit bold :foreground "yellow"))
")")))))
(unless (zerop (length output))
output))))))
(eshell-starship-defmodule git
:predicate (lambda ()
(eq (vc-responsible-backend default-directory t) 'Git))
:color "medium purple"
:icon "󰊢 "
:reload-on 'always
:action 'eshell-starship--git-status)
;;; Non-git VC module
(defun eshell-starship--vc-status () (defun eshell-starship--vc-status ()
"Get vc status for `eshell-starship--prompt-function'." "Get vc status for `eshell-starship--prompt-function'."
(if-let (backend (vc-responsible-backend default-directory t)) (when-let ((backend (vc-responsible-backend default-directory t))
(if (eq backend 'Git) ((not (eq backend 'Git))))
(let ((status (eshell-starship--git-status))) (downcase (symbol-name backend))))
(and (not (zerop (length status))) status))
(propertize
(concat "" (downcase (symbol-name backend)))
'face '(:foreground "purple")))))
(eshell-starship-defmodule vc (eshell-starship-defmodule vc
:predicate 'always :predicate 'always
:allow-remote nil :allow-remote nil
:reload-on 'always :reload-on 'always
:color "purple"
:icon ""
:action 'eshell-starship--vc-status :action 'eshell-starship--vc-status
:doc "The working directory's version control status.") :doc "The working directory's version control status (other than git).")
;;; Timer module ;;; Timer module
@ -421,7 +439,8 @@ For example, a revert. If there is no current operation, return nil."
eshell-starship--last-end-time eshell-starship--last-end-time
(eshell-starship-format-span (- eshell-starship--last-end-time (eshell-starship-format-span (- eshell-starship--last-end-time
eshell-starship--last-start-time))) eshell-starship--last-start-time)))
(setq eshell-starship--last-start-time nil))) (setq eshell-starship--last-start-time nil
eshell-starship--last-end-time nil)))
(eshell-starship-defmodule cmd-time (eshell-starship-defmodule cmd-time
:prefix "took " :prefix "took "
@ -671,6 +690,17 @@ The test is performed relative to `default-directory'."
(and extensions (apply' eshell-starship--exts-exist-p extensions)) (and extensions (apply' eshell-starship--exts-exist-p extensions))
(and predicate (funcall predicate))))))) (and predicate (funcall predicate)))))))
(defun eshell-starship--propertize-face (str append &rest faces)
"Copy STR and add FACES to its text properties.
This uses `add-face-text-property' internally, so it will add to existing `face'
properties. If STR is nil, return an empty string. If APPEND, give priority to
existing faces."
(if (not str)
""
(let ((copy (copy-sequence str)))
(dolist (face faces copy)
(add-face-text-property 0 (length copy) face append copy)))))
(defun eshell-starship--execute-module (module) (defun eshell-starship--execute-module (module)
"Run the module MODULE and return its output. "Run the module MODULE and return its output.
Also cache the time it took to run it and its output." Also cache the time it took to run it and its output."
@ -681,11 +711,17 @@ Also cache the time it took to run it and its output."
result (funcall action) result (funcall action)
end-time (float-time)) end-time (float-time))
(when-let ((result) (when-let ((result)
(output (concat prefix (output
(concat prefix
(eshell-starship--propertize-face
icon t
(when color
(list (list :foreground color)))
'eshell-starship-icon-face)
(if color (if color
(propertize (concat icon result) (eshell-starship--propertize-face
'face `(:foreground ,color)) result t (list :foreground color))
(concat icon result)) result)
postfix))) postfix)))
(puthash name (list t output (cons (- end-time start-time) (puthash name (list t output (cons (- end-time start-time)
(take 9 oldtimes))) (take 9 oldtimes)))

View File

@ -2002,7 +2002,9 @@ If no name is given, list all bookmarks instead."
:demand t :demand t
:hook (eshell-prompt-mode . eshell-starship-prompt-mode) :hook (eshell-prompt-mode . eshell-starship-prompt-mode)
:config :config
(eshell-starship-setup-evil-keybindings)) (eshell-starship-setup-evil-keybindings)
(set-face-attribute 'eshell-starship-icon-face nil
:family "FiraCode Nerd Font"))
;; proced ;; proced
(use-package proced (use-package proced