diff options
Diffstat (limited to 'emacs')
-rw-r--r-- | emacs/custom/fcuny-eshell.el | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/emacs/custom/fcuny-eshell.el b/emacs/custom/fcuny-eshell.el index 0476b2f..29495ef 100644 --- a/emacs/custom/fcuny-eshell.el +++ b/emacs/custom/fcuny-eshell.el @@ -1,6 +1,14 @@ +;;; fcuny-eshell.el --- Configure eshell +;;; Commentary: +;;; Code: + +(require 'use-package) +(require 'magit) + (require 'eshell) (require 'esh-mode) (require 'esh-module) + (setq eshell-modules-list '(eshell-alias eshell-basic @@ -27,6 +35,7 @@ (require 'em-prompt) (defun fcuny/eshell-mode-setup () + "Configures various aliases for eshell." (eshell/alias "e" "find-file $1") (eshell/alias "emacs" "find-file $1") (eshell/alias "ee" "find-file-other-window $1") @@ -44,15 +53,16 @@ (eshell/alias "agenda" "org-agenda") - ;; Disable current line highlighting. + ;; Disable current line highlighting. (setq-local global-hl-line-mode nil)) (defun eshell/gst (&rest args) + "Alias for git-status using magit, with optional ARGS." (magit-status (pop args) nil) (eshell/echo)) ;; The echo command suppresses output (defun fcuny/eshell--open-or-cd (path) - "Cd to PATH if path is a directory ((file-name-directory path) => t), otherwise open PATH via `find-file'." + "Cd to PATH if path is a directory, otherwise open PATH via `find-file'." (interactive) (if (file-directory-p path) (progn @@ -64,6 +74,7 @@ (find-file path))) (defun fcuny/eshell-open-file-at-point () + "Open the file at point in a buffer." (interactive) (let ((filename (symbol-name (symbol-at-point)))) (cond @@ -73,9 +84,10 @@ (fcuny/eshell--open-or-cd (expand-file-name filename)))))) (defun fcuny/shorten-path (path &optional max-len) - "Return a potentially trimmed-down version of the directory PATH, replacing -parent directories with their initial characters to try to get the character -length of PATH (sans directory slashes) down to MAX-LEN." + "Return a potentially trimmed-down version of the directory PATH. +Replacing parent directories with their initial characters to try +to get the character length of PATH (sans directory slashes) down +to MAX-LEN." (let* ((components (split-string (abbreviate-file-name path) "/")) (host (propertize (system-name) 'face `(:background "#4ba9aa"))) (max-len (or max-len 30)) @@ -99,9 +111,10 @@ length of PATH (sans directory slashes) down to MAX-LEN." (concat host " " str (cl-reduce (lambda (a b) (concat a "/" b)) components)))) (defun fcuny/eshell-prompt () - "Sets the prompt for eshell. If the current path is on a remote -host and starts with `ssh:', then we replace the prompt with -`@<hostname>' to indicate we're on a remote host." + "Sets the prompt for eshell. +If the current path is on a remotehost and starts with `ssh:', +then we replace the prompt with `@<hostname>' to indicate we're +on a remote host." (concat (let ((absolute-path (eshell/pwd))) (if (string-match "/ssh:\\(.+\\):" absolute-path) @@ -110,9 +123,9 @@ host and starts with `ssh:', then we replace the prompt with (if (= (user-uid) 0) " # " " $ "))) (defun fcuny/eshell-here () - "Opens up a new shell in the directory associated with the current -buffer's file. The eshell is renamed to match that directory to make -multiple eshell windows easier." + "Opens a new shell in the directory associated with the current buffer's file. +The eshell is renamed to match that directory to make multiple +eshell windows easier." (interactive) (let* ((parent (if (buffer-file-name) (file-name-directory (buffer-file-name)) @@ -126,6 +139,7 @@ multiple eshell windows easier." (eshell-send-input))) (defun fcuny/eshell-main () + "Create a buffer for eshell." (eshell "new") (rename-buffer "*eshell: main session*") (insert "ls -l") @@ -166,19 +180,22 @@ append to it, while separating multiple outputs with ;; https://www.birkey.co/2021-06-20-why-eshell-part-1.html (defun fcuny/eshell-current-command-start () + "Capture the time for when the command is started." (setq eshell-current-command-start-time (current-time))) (defun fcuny/eshell-current-command-stop () + "Calculate how long the command took to run." (when eshell-current-command-start-time (let ((elapsed-time (float-time - (time-subtract (current-time) - eshell-current-command-start-time)))) + (time-subtract (current-time) + eshell-current-command-start-time)))) (if (> elapsed-time 5) (eshell-interactive-print - (format "Finished in: %.0fs\n" elapsed-time))))) - (setq eshell-current-command-start-time nil)) + (format "Finished in: %.0fs\n" elapsed-time))))) + (setq eshell-current-command-start-time nil)) (defun fcuny/eshell-current-command-time-track () + "Track how long command takes to run." (add-hook 'eshell-pre-command-hook #'fcuny/eshell-current-command-start nil t) (add-hook 'eshell-post-command-hook #'fcuny/eshell-current-command-stop nil t)) @@ -211,3 +228,4 @@ append to it, while separating multiple outputs with :hook (eshell-mode . eshell-bookmark-setup)) (provide 'fcuny-eshell) +;;; fcuny-eshell.el ends here |