- In any shell within Emacs, run M-x
sticky-shell-modeto enable the mode locally. - To enable the mode for all shell buffers, run M-x
sticky-shell-global-mode.
The mode should work in any shell that inherits: eshell-mode, comint-mode, vterm-mode, term-mode. It should be easy to add support for additional modes (see sticky-shell-supported-modes).
If you’d like to add better support for any additional modes, please let me know.
All language-interpreters I could try (Python, Clojure, Emacs-Lisp) derive from comint-mode.
If you find a shell for which the mode doesn’t work, please let me know.
The package is available through MELPA. To install from there:
- Make sure MELPA is in your package archives
(require 'package) (add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
Then:
- M-x
package-refresh-contents - M-x
package-installsticky-shell
You can install and configure with use-package:
(use-package sticky-shell
:ensure t ; install
;; add your customization here
)The customizable variables are:
sticky-shell-get-promptthe function determining which prompt to show. The available options are:sticky-shell-latest-promptsticky-shell-prompt-above-visiblesticky-shell-prompt-above-cursor
(see the functions’ doc strings for a detailed explanation)
You can also write your own function and assign it to this variable.
sticky-shell-supported-modesa property list of modes. Each mode is associated with the function needed to navigate to a previous prompt. For example('eshell-mode #'eshell-previous-prompt).You can implement support for additional modes by adding to this list. Your choice of
sticky-shell-get-promptwill then use this*-previous-promptfunction to retrieve the correct prompt.
At times, a prompt is too long to fit within a one-line header. For these cases, sticky-shell-shorten-header-mode can be used to shorten the prompt, ensuring that the beginning and end of the prompt are always visible within the header (see fourth screenshot).
This mode can be enabled or disabled with the usual mechanism (calling the sticky-shell-shorten-header-mode function).
If you wish for the header to be shortened by default, add sticky-shell-shorten-header-set-mode to the sticky-shell-mode-hook. This function ensures that sticky-shell-shorten-header-mode is enabled/disabled together with sticky-shell-mode.
Note that sticky-shell-shorten-header-mode doesn’t work properly in term-mode and vterm-mode.
This is not because of an issue with sticky-shell-shorten-header-mode itself, but because sticky-shell-mode uses (thing-at-point 'line) to read a prompt: in terminal modes, this function returns a line within the borders of a window rather than up to the first newline character. The result is that the header will always be cut-off at the window-border.
Right now I’d rather keep this general implementation simple rather than over-fit for these particular modes.
You can always define your own sticky-shell-get-prompt function that works as desired: if this function returns a string that doesn’t fit fully within one line, sticky-shell-shorten-header-mode would work as usual.
A comint shell using sticky-shell-prompt-above-visible
An eshell using sticky-shell-prompt-above-cursor
An eshell using sticky-shell-shorten-header-mode with sticky-shell-prompt-above-cursor
Please contact me here if you’d like to add features or if you encounter any issues while using this package.
