eshell: Setup some helper functions in eshell-additions, move bindings to there.
- A helper function to instantly perform commands - eshell-goto-latest-prompt to remove any artifacts when performing these instant commands Bindings needed to be moved over to that section cos they utilise these helpers.
This commit is contained in:
@@ -1825,44 +1825,13 @@ interpreter.
|
|||||||
(evil-set-initial-state 'eshell-mode 'normal)
|
(evil-set-initial-state 'eshell-mode 'normal)
|
||||||
|
|
||||||
(defun +eshell/banner-message ()
|
(defun +eshell/banner-message ()
|
||||||
(concat (shell-command-to-string "fortune") "\n"))
|
(concat (shell-command-to-string "fortune | cowsay -r") "\n"))
|
||||||
|
|
||||||
(setq eshell-cmpl-ignore-case t
|
(setq eshell-cmpl-ignore-case t
|
||||||
eshell-cd-on-directory t
|
eshell-cd-on-directory t
|
||||||
eshell-cd-shows-directory nil
|
eshell-cd-shows-directory nil
|
||||||
eshell-highlight-prompt nil
|
eshell-highlight-prompt nil
|
||||||
eshell-banner-message '(+eshell/banner-message))
|
eshell-banner-message '(+eshell/banner-message)))
|
||||||
|
|
||||||
(defun +eshell/good-clear ()
|
|
||||||
(interactive)
|
|
||||||
(eshell/clear-scrollback)
|
|
||||||
(eshell-send-input))
|
|
||||||
|
|
||||||
(add-hook
|
|
||||||
'eshell-mode-hook
|
|
||||||
(defun +eshell/--setup-keymap nil
|
|
||||||
(interactive)
|
|
||||||
(general-def
|
|
||||||
:states '(normal insert visual)
|
|
||||||
:keymaps 'eshell-mode-map
|
|
||||||
"M-j" #'eshell-next-prompt
|
|
||||||
"M-k" #'eshell-previous-prompt
|
|
||||||
"C-j" #'eshell-next-matching-input-from-input
|
|
||||||
"C-k" #'eshell-previous-matching-input-from-input)
|
|
||||||
|
|
||||||
(local-leader
|
|
||||||
:keymaps 'eshell-mode-map
|
|
||||||
"g" (proc-int
|
|
||||||
(let ((buffer (current-buffer)))
|
|
||||||
(eshell/goto)
|
|
||||||
(with-current-buffer buffer
|
|
||||||
(eshell-send-input))))
|
|
||||||
"l" (proc-int
|
|
||||||
(eshell-return-to-prompt)
|
|
||||||
(insert "ls")
|
|
||||||
(eshell-send-input))
|
|
||||||
"c" #'+eshell/good-clear
|
|
||||||
"k" #'eshell-kill-process))))
|
|
||||||
#+end_src
|
#+end_src
|
||||||
*** EShell prompt
|
*** EShell prompt
|
||||||
Here I use my external library
|
Here I use my external library
|
||||||
@@ -1888,6 +1857,10 @@ Using my external library
|
|||||||
internal EShell commands and a command to open EShell at the current
|
internal EShell commands and a command to open EShell at the current
|
||||||
working directory.
|
working directory.
|
||||||
|
|
||||||
|
I use these commands in my local bindings for EShell so I also setup
|
||||||
|
those here - they need to be hooked into the mode initialisation
|
||||||
|
because of how EShell works unfortunately.
|
||||||
|
|
||||||
NOTE: I don't defer this package because it must be loaded *before*
|
NOTE: I don't defer this package because it must be loaded *before*
|
||||||
EShell is. This is because any ~eshell/*~ functions need to be loaded
|
EShell is. This is because any ~eshell/*~ functions need to be loaded
|
||||||
before launching it.
|
before launching it.
|
||||||
@@ -1899,6 +1872,30 @@ before launching it.
|
|||||||
;; FIXME: Why do I need to double load this? Otherwise +eshell/open doesn't
|
;; FIXME: Why do I need to double load this? Otherwise +eshell/open doesn't
|
||||||
;; work as intended when using universal argument.
|
;; work as intended when using universal argument.
|
||||||
(load-file (concat user-emacs-directory "elisp/eshell-additions.el"))
|
(load-file (concat user-emacs-directory "elisp/eshell-additions.el"))
|
||||||
|
|
||||||
|
(add-hook
|
||||||
|
'eshell-mode-hook
|
||||||
|
(defun +eshell/--setup-keymap nil
|
||||||
|
(interactive)
|
||||||
|
(general-def
|
||||||
|
:states '(normal insert visual)
|
||||||
|
:keymaps 'eshell-mode-map
|
||||||
|
"M-j" #'eshell-next-prompt
|
||||||
|
"M-k" #'eshell-previous-prompt
|
||||||
|
"C-j" #'eshell-next-matching-input-from-input
|
||||||
|
"C-k" #'eshell-previous-matching-input-from-input)
|
||||||
|
|
||||||
|
(local-leader
|
||||||
|
:keymaps 'eshell-mode-map
|
||||||
|
"g" (proc-int
|
||||||
|
(let ((buffer (current-buffer)))
|
||||||
|
(eshell/goto)
|
||||||
|
(with-current-buffer buffer
|
||||||
|
(eshell-send-input))))
|
||||||
|
"l" (proc-int (eshell-send-command "ls"))
|
||||||
|
"c" (proc-int (eshell-send-command "clear"))
|
||||||
|
"k" #'eshell-kill-process)))
|
||||||
|
|
||||||
:general
|
:general
|
||||||
(shell-leader
|
(shell-leader
|
||||||
"t" #'+eshell/open)
|
"t" #'+eshell/open)
|
||||||
|
|||||||
@@ -28,23 +28,41 @@
|
|||||||
(autoload #'eshell/echo "eshell")
|
(autoload #'eshell/echo "eshell")
|
||||||
(autoload #'eshell/send-input "eshell")
|
(autoload #'eshell/send-input "eshell")
|
||||||
|
|
||||||
|
;; General helpers
|
||||||
|
(defun eshell-goto-latest-prompt ()
|
||||||
|
"Move point to the most recent eshell prompt and clear anything before it."
|
||||||
|
(interactive)
|
||||||
|
(goto-char (point-max))
|
||||||
|
(eshell-bol)
|
||||||
|
(delete-region (point) (point-max)))
|
||||||
|
|
||||||
|
(defun eshell-send-command (cmd)
|
||||||
|
(interactive "sCommand: ")
|
||||||
|
(eshell-goto-latest-prompt)
|
||||||
|
(insert cmd)
|
||||||
|
(eshell-send-input))
|
||||||
|
|
||||||
;; Aliases
|
;; Aliases
|
||||||
(defun eshell/goto (&rest args)
|
(defun eshell/goto (&rest args)
|
||||||
"Use `read-directory-name' to change directories"
|
"Use `read-file-name' to change directories"
|
||||||
(let* ((name (read-file-name "Choose file: "))
|
(let* ((name (read-file-name "Choose file: " (thing-at-point 'filename t)))
|
||||||
(dir (file-name-directory name)))
|
(dir (file-name-directory name)))
|
||||||
|
(eshell-goto-latest-prompt)
|
||||||
(eshell/cd (list dir))
|
(eshell/cd (list dir))
|
||||||
(if (not (file-directory-p name))
|
(if (not (file-directory-p name))
|
||||||
(find-file name))))
|
(find-file name))))
|
||||||
|
|
||||||
(defun eshell/project-root (&rest args)
|
(defun eshell/project-root (&rest args)
|
||||||
"Change to directory `project-root'"
|
"Change to directory `project-root'"
|
||||||
(if (project-current)
|
(cond
|
||||||
(eshell/cd (list (project-root (project-current))))
|
((project-current)
|
||||||
|
(eshell-goto-latest-prompt)
|
||||||
|
(eshell/cd (list (project-root (project-current)))))
|
||||||
|
(t
|
||||||
(setq eshell-last-command-status 1)
|
(setq eshell-last-command-status 1)
|
||||||
(eshell/echo
|
(eshell/echo
|
||||||
(format "[%s]: No project in current directory"
|
(format "[%s]: No project in current directory"
|
||||||
(propertize "Error" 'font-lock-face '(:foreground "red"))))))
|
(propertize "Error" 'font-lock-face '(:foreground "red")))))))
|
||||||
|
|
||||||
(defun eshell/sudo-switch (&rest args)
|
(defun eshell/sudo-switch (&rest args)
|
||||||
"Switch to and from administrative (sudo) mode in Eshell.
|
"Switch to and from administrative (sudo) mode in Eshell.
|
||||||
@@ -57,7 +75,7 @@ Uses tramp to figure out if we're in sudo mode or not. "
|
|||||||
((string= user "root")
|
((string= user "root")
|
||||||
(eshell/cd (file-remote-p default-directory 'localname))))))
|
(eshell/cd (file-remote-p default-directory 'localname))))))
|
||||||
|
|
||||||
;; Additional functions
|
;; +eshell/open and +eshell/at-cwd
|
||||||
(defun +eshell/--current-instances ()
|
(defun +eshell/--current-instances ()
|
||||||
(cl-loop for buffer being the buffers
|
(cl-loop for buffer being the buffers
|
||||||
if (with-current-buffer buffer
|
if (with-current-buffer buffer
|
||||||
|
|||||||
Reference in New Issue
Block a user