emacs/lisp/eshell-settings.el
2022-07-17 13:35:17 -08:00

62 lines
2.1 KiB
EmacsLisp

;;; eshell-settings --- settings for eshell.
;;; Commentary:
;; the elisp linter wants me to put some text here so I guess I will
;;; Code:
(require 'eshell)
(defun eshell/emacs (&rest args)
"Basically you can edit ARGS and it will open in a new buffer.
When your shell is Emacs, your Emacs is but an oyster...
This is taken from a website that I can't remember at the moment."
(if (null args)
(bury-buffer)
(mapc
#'find-file-other-window
(mapcar
#'expand-file-name (eshell-flatten-list (reverse args))))))
(defun eshell/clear ()
"Clear the scrollback buffer, like `clear' in a real shell..."
(eshell/clear-scrollback))
(defun eshell/faketty (&rest args)
"USAGE: `faketty ARGS` where ARGS is anything that spews colors.
Credit: https://stackoverflow.com/questions/1401002/how-to-trick-an-application-into-thinking-its-stdout-is-a-terminal-not-a-pipe"
(shell-command-to-string
(format "script -qfc %s /dev/null" args)))
(defun with-face (str &rest face-plist)
(propertize str 'face face-plist))
(defun custom-eshell-prompt ()
(let* (
;; Get the git branch.
(git-branch-unparsed
(shell-command-to-string "git rev-parse --abbrev-ref HEAD 2>/dev/null"))
(git-branch
(if (string= git-branch-unparsed "")
""
;; Remove the trailing newline.
(substring git-branch-unparsed 0 -1)))
)
(concat
;; Timestamp.
;; (with-face
;; (format-time-string "[%a, %b %d | %H:%M:%S]\n" (current-time))
;; :inherit font-lock-builtin-face)
;; Directory.
(with-face (concat (airline-shorten-directory default-directory (/ (window-width) 2)) " ") :inherit font-lock-constant-face)
;; Git branch.
(unless (string= git-branch "")
(with-face (concat "[" git-branch "]") :inherit font-lock-string-face))
"\n"
;; Prompt.
;; NOTE: Need to keep " $" for the next/previous prompt regexp to work.
(with-face ">" :inherit font-lock-preprocessor-face)
" "
)))
(setq eshell-prompt-function 'custom-eshell-prompt)
(setq eshell-highlight-prompt nil)
(provide 'eshell-settings)
;;; eshell-settings.el ends here