diff options
-rw-r--r-- | eshell-conf.el | 97 |
1 files changed, 84 insertions, 13 deletions
diff --git a/eshell-conf.el b/eshell-conf.el index 0b191cb..588a088 100644 --- a/eshell-conf.el +++ b/eshell-conf.el @@ -33,7 +33,7 @@ (require 'ring) (require 'type-break) -;; Measure time of commands and display automatically. +;;; Measure time of commands and display automatically. ;;;###autoload (defvar-local eshell-current-command-start-time nil @@ -45,10 +45,12 @@ ;;;###autoload (defun eshell-current-command-start () + "Record the start time of the command." (setq-local eshell-current-command-start-time (current-time))) ;;;###autoload (defun eshell-current-command-stop () + "Record the stop time of the last command." (cond ((timep eshell-current-command-start-time) (let* ((elapsed-time (time-since eshell-current-command-start-time)) @@ -58,7 +60,7 @@ (format-seconds "%yy %dd %hh %mm %ss%z" elapsed-time-int)) (microseconds (caddr elapsed-time-list)) (micro-str - (cond ((or (>= elaped-time-int 1) (> microseconds 10000)) + (cond ((or (>= elapsed-time-int 1) (> microseconds 10000)) (format "%dμs" microseconds))))) (setq eshell-prompt-time-string (mapconcat #'identity @@ -69,6 +71,7 @@ ;;;###autoload (defun eshell-current-command-time-track () + "Add hooks to track command times." (add-hook 'eshell-pre-command-hook #'eshell-current-command-start nil t) (add-hook 'eshell-post-command-hook #'eshell-current-command-stop nil t)) @@ -82,6 +85,7 @@ ;;;###autoload (defun eshell-stop-track-command-time () + "Stop tracking the execution times of commands." (remove-hook 'eshell-pre-command-hook #'eshell-current-command-start t) (remove-hook 'eshell-post-command-hook #'eshell-current-command-stop t) (remove-hook 'eshell-mode-hook #'eshell-current-command-time-track)) @@ -89,7 +93,7 @@ ;;;###autoload (defun durand-eshell-emit-prompt () "Emit a prompt if eshell is being used interactively. -Add a time information at the beginning. -- Modified by Durand." +Add a time information at the beginning. -- Modified by Durand." (when (boundp 'ansi-color-context-region) (setq ansi-color-context-region nil)) (run-hooks 'eshell-before-prompt-hook) @@ -121,7 +125,7 @@ Add a time information at the beginning. -- Modified by Durand." (advice-add #'eshell-emit-prompt :override #'durand-eshell-emit-prompt) -;; Eshell sets the keymap in the major mode function... +;;; Eshell sets the keymap in the major mode function ;;;###autoload (add-hook 'eshell-mode-hook #'durand-set-eshell-keys) @@ -132,9 +136,11 @@ Add a time information at the beginning. -- Modified by Durand." (define-key eshell-mode-map (vector #xf) ; C-o #'eshell-clear)) +;;; YouTube URL + ;;;###autoload (defun eshell/yt-url (&rest args) - "Run `durand-convert-youtube-video-to-url' on the first arg." + "Run `durand-convert-youtube-video-to-url' on the first of ARGS." (eshell-eval-using-options "yt-url" args '((?o "open" nil open-p "Open in the default external browser.") @@ -146,7 +152,7 @@ Add a time information at the beginning. -- Modified by Durand." ;;;###autoload (defun eshell-yt-url (&optional video-name open-p) - "Save the URL of a video downloaded from YouTube to the kill-ring. + "Save the URL of a video downloaded from YouTube to the `kill-ring'. The video is given by VIDEO-NAME. If OPEN-P is non-nil, then open the video in the default external @@ -159,6 +165,8 @@ browser instead." (open-p (browse-url-default-browser url)) ((kill-new url))))) +;;; Clear screen + ;;;###autoload (defun eshell-clear (num) "Deletes the buffer. @@ -173,10 +181,15 @@ Do NUM times `eshell-previous-prompt' before deleting." (eshell-previous-prompt num) (line-beginning-position))))) +;;; Jump + +;; NOTE: This should be replaced by the bookmarks of Emacs. + ;;;###autoload (defun eshell/j (&rest args) "Implementation of `j'. -See `eshell-j' for the actual functionality." +See `eshell-j' for the actual functionality and for the format of +ARGS." (eshell-eval-using-options "j" args '((?r "recent" 'exclusive use-recent-p "Find in recent directories instead of symbolic links.") @@ -189,7 +202,7 @@ See `eshell-j' for the actual functionality." (defun eshell/mark (&rest args) "Add symbolic links to `eshell-mark-directory'. The argument ARGS should be list of one string which names the -link name. If no argument is given, the base name of the current +link name. If no argument is given, the base name of the current directory is used." ;; (setq args (cons default-directory args)) ;; (setq args (durand-eshell-delete-dups args :test #'string=)) @@ -226,15 +239,15 @@ ARGS should be a property list specifying tests and keys. If the keyword argument TEST is non-nil, it should be a function with two arguments which tests for equality of elements in the -sequence. The default is the function `equal'. +sequence. The default is the function `equal'. If the keyword argument TEST is non-nil, it should be a function with two arguments which tests for equality of elements in the -sequence. The default is the function `equal'. +sequence. The default is the function `equal'. If the keyword argument KEY is non-nil, it should be a function with one argument which returns the key of the element in the -sequence to be compared by the test function. The default is the +sequence to be compared by the test function. The default is the function `identity'. Note that this function is not supposed to change global state, @@ -347,12 +360,16 @@ candidates." (completing-read "Choose a link: " candidates nil t)) candidates #'string=)))))))) +;;; convenient ls + ;;;###autoload (defun eshell/l (&rest args) "Equivalent with ls -ahl ARGS. If called without ARGS, then use ./ instead." (eshell/ls "-hal" (or args "./"))) +;;; Substitute commands + ;;;###autoload (defun eshell/r (&rest args) "Replace the last command by the specifications in ARGS." @@ -373,7 +390,7 @@ REPLACE." ;;;###autoload (defun eshell-r (args &optional last-number) "Replace the LAST-NUMBER th command by ARGS. -ARGS are pairs of the form MATCH=REPLACE. This command will find +ARGS are pairs of the form MATCH=REPLACE. This command will find the last command, or the LAST-NUMBER-th command if LAST-NUMBER is non-nil, and replace the first match of MATCH by REPLACE. @@ -429,16 +446,70 @@ other value means 1." (= (aref nth-last-command 0) ?r) (or (= (length nth-last-command) 1) (= (aref nth-last-command 1) 32))) - (user-error "Repeating a repeating command. This is probably not what you want"))) + (user-error "Repeating a repeating command. This is probably not what you want"))) (eshell-command-result nth-last-command))) +;;; Expand history + (add-to-list 'eshell-expand-input-functions #'eshell-expand-history-references) +;;; Visual commands + (add-to-list 'eshell-visual-commands "mpv" nil #'string=) +;;; List files after changing directories + (setq eshell-list-files-after-cd t) +;;; Eshell bookmark handler + +(defun durand-eshell-bookmark-jump (bookmark) + "Handle Eshell BOOKMARK in my preferred way." + (let ((handler (bookmark-get-handler bookmark)) + (location (bookmark-prop-get bookmark 'location)) + (eshell-buffers + (delq + nil + (mapcar + (lambda (buffer) + (cond + ((provided-mode-derived-p + (buffer-local-value + 'major-mode buffer) + 'eshell-mode) + buffer))) + (buffer-list))))) + (cond + ((and (stringp location) + (not (string= location "")) + (memq handler (list #'eshell-bookmark-jump + #'durand-eshell-bookmark-jump))) + (let (reuse-p) + (mapc + (lambda (buffer) + (cond + ((string= (buffer-local-value 'default-directory + buffer) + location) + (setq reuse-p buffer)))) + eshell-buffers) + ;; Don't switch to that buffer, otherwise it will cause + ;; problems if we want to open the bookmark in another window. + (cond + (reuse-p (set-buffer reuse-p)) + ;; eshell will pop the buffer + ((let ((buffer (generate-new-buffer eshell-buffer-name))) + (with-current-buffer buffer + (setq-local default-directory location) + (eshell-mode)) + (set-buffer buffer)))))) + ((user-error "Cannot jump to this bookmark"))))) + +(advice-add #'eshell-bookmark-jump + :override + #'durand-eshell-bookmark-jump) + (provide 'eshell-conf) ;;; eshell-conf.el ends here |