Is there any terminal shell/emulator out there that supports editing your current command with the mouse?

Specifically things like placing the cursor by clicking (useful for long commands) or double clicking and pressing delete to select and delete a word etc.

For example, the terminal at the bottom of Midnight Commander (mc) has support for placing the cursor by mouse click. I'm looking for something similar that is more terminal-focused, as mc is mainly a file manager.

It's fine if it only works under a GUI environment (I'm on Ubuntu 18.04 with GNOME3).

  • 2
    Midnight Commander is as much a terminal application as any other, and what you are looking for is shells, that understand mouse input because their ZLE/libedit/Readline libraries do. The terminal emulators have provided mouse input capabilities for years. What you are looking for is shells that enable and understand such input.
    – JdeBP
    May 18 '18 at 14:19
  • I could also imagine a terminal emulator (use whatever word) that would fully work like a normal GUI application, say like MATLAB, where you can properly edit your command in the modern way with a thin line cursor, right click menus etc., then press enter and then the whole line would be given to bash as one command. However I can see how this would be problematic for interactive terminal applications. I'm just brainstorming because I find the current ways quite inconvenient.
    – isarandi
    May 18 '18 at 14:30
  • That wouldn't work, ironically because the ZLE/libedit/Readline libraries would get in the way. In the POSIX General Terminal Interface architecture, editing is either a function of the applications softwares themselves (such as shells with ZLE/libedit/Readline) or of the line discipline when in canonical mode. Terminals are not block mode and there is no local editing. What you are looking for is shells where the editor library knows about mouse reports.
    – JdeBP
    May 18 '18 at 15:10

zsh can be extended to support mouse operation like you describe, using Stéphane Chazelas’ mouse.zsh ZLE widget:

wget http://stchaz.free.fr/mouse.zsh
. ./mouse.zsh

(and once you’ve tested it, add it to your ~/.zshrc).

It will work in any terminal with VT200 mouse tracking, and in the Linux console with gpm.

  • 1
    This goes in the right direction, but unfortunately the mouse can either be used to edit the current command or to select text from previous outputs but not both at the same time.
    – isarandi
    May 18 '18 at 19:22
  • @isarandi it’s a bit complicated to provide both simultaneously in this kind of context, within an existing terminal. If you bind zle-toggle-mouse to a key, as suggested in the documentation, you can toggle the behaviour even while you’re editing a command, which alleviates the problem somewhat... May 18 '18 at 19:31

while not builtin, you can install package gpm:

$ sudo apt-get install gpm

$ sudo /etc/init.d/gpm stop | start

works well for CTRL+ALT+Fx console, with any shell

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.