szermatt / mistty

Shell/Comint alternative with a fully functional terminal for Emacs 29.1 and later.
GNU General Public License v3.0
102 stars 5 forks source link
emacs fish-shell shell

MisTTY, a shell/comint alternative with a fully functional terminal

CI Status Documentation Status MELPA MELPA Stable

MisTTY is a major mode for Emacs 29.1 and up that runs a shell inside of a buffer, similarly to comint mode. It is built on top of term.el.

M-x mistty creates a buffer with an interactive shell. See launching for details.

MisTTY feels very much like comint mode: you can move around freely and run any Emacs command you want - until you press TAB and end up with the native completion or notice the shell autosuggestions. With MisTTY you have access to both Emacs and the shell commands and editing tools. Like comint, MisTTY supports remote shells with TRAMP.

Additionally, commands that take over the entire screen, such as less or vi also work, temporarily taking over the window, while scrollback remains available in another buffer.

MisTTY works well with Bash and ZSH, but it is especially well suited to running Fish: you get autosuggestions, completion in full colors. Here's what the end result might look like:

screen grab

MisTTY is known to work on Linux and MacOS. It also supports non-shell command-line programs, such as python.

COMPARISON

MisTTY isn't a terminal emulator, but rather a frontend to an existing terminal emulator, the built-in term.el. Its goal is to make it more convenient to use while inside of Emacs and better integrate with Emacs itself. In theory, other terminal emulators than term.el might be used as engine for MisTTY, such as vterm and eat.

MisTTY has some similarities with coterm; it offers the same switch between full-screen and line mode.

Coterm, ansi-term and eat all have a line mode, just like comint. While in line mode, rendering is done by Emacs and editing commands are Emacs commands. In constrast, with MisTTY, all rendering is done by the shell through the terminal. This is why native shell completion and autosuggestion is available with MisTTY and not with these other line modes and why you can freely mix shell commands with Emacs commands while editing the command line.

ansi-term and eat also have a char mode, where rendering and command execution is handled by the shell, and editing with Emacs isn't available. The difference with MisTTY is then that MisTTY makes Emacs editing commands available when possible.

eat also has a semi-char mode, which is the closest there is to MisTTY. In that mode, Emacs movements commands are available. However, Emacs commands that modify the buffer, aren't available to edit the command line. In contrast, MisTTY allows Emacs to navigate to and edit the whole buffer, then replays changes made to the command-line.

INSTALLATION

The following is just a quick introduction. Read the full documentation at https://mistty.readthedocs.io/en/latest/

You can install MisTTY:

USAGE

Type M-x mistty to launch a new shell buffer in MisTTY mode, then use it as you would comint.

You'll quickly notice some differences. For example TAB completion working just like in a terminal instead of relying of Emacs completion.

The purple line on the left indicates the portion of the buffer that's a terminal. What you type in there gets sent to the program, usually a shell, and translated by that program. The rest of the buffer is normal, editable, text.

Commands that takes the whole screen such as less or vi take you into terminal mode for the duration of that command. You can still access previous commands in the "scrollback" MisTTY buffer by typing C-c C-j.

If you ever get into a situation where a command needs you to press keys normally sent to Emacs, such as the arrow keys, press C-c C-q. It'll send all key strokes directly to the terminal until you exit the mode by pressing C-g. To send a single key to the terminal you can also press C-q <key> instead.

You will very likely want to send some keys you use often directly to the terminal. This is done by binding keys to mistty-send-key in mistty-prompt-map. For example:

(use-package mistty
  :bind (("C-c s" . mistty)

         ;; bind here the shortcuts you'd like the
         ;; shell to handle instead of Emacs.
         :map mistty-prompt-map

         ;; fish: directory history
         ("M-<up>" . mistty-send-key)
         ("M-<down>" . mistty-send-key)
         ("M-<left>" . mistty-send-key)
         ("M-<right>" . mistty-send-key)))

In addition to that, unless you're using Bash, which supports it out of the box, you'll also likely want to enable directory tracking in your shell.

See also the documentation for more details on configuring MisTTY .

SOMETHING IS WRONG !

Please check the FAQ and, if that doesn't help, take the time to file a bug report.

CONTRIBUTING

See the Contributing section of the documentation.

COMPATIBILITY

MisTTY requires Emacs 29.1 or later.