17

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).

4
  • 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, 2018 at 14:19
  • 1
    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, 2018 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, 2018 at 15:10
  • Konsole from KDE (and other terminals) do this for copy and paste by default. The challenge is for cut and delete.
    – alchemy
    Aug 8, 2023 at 22:10

2 Answers 2

14

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
zle-toggle-mouse

(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.

4
  • 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, 2018 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, 2018 at 19:31
  • 1
    For the record, I (the author) never really used it in the end. It was more to see if it could be done. It was also written almost 20 years ago, it could probably be improved to use newer features of zsh. I've noticed a few forks on github with some improvements. IIRC it was pulled into oh-my-zsh at some point, I don't know if it's still there. Jun 21, 2022 at 13:21
  • @StéphaneChazelas (btw, im a big fan of your contributions) I'm trying to take a crack at getting ctrl+shift+left/right (or alt+left/right) for selection and maybe cut working.. the plugin didnt change much for me.. any ideas? I sourced it in .zshrc but Konsole already has mouse copy and paste.. cut doesnt seem to work (maybe it wasnt intended to do that). Any idea how I might map alt+right ^[[1;3C to mouse drag right selection?
    – alchemy
    Aug 8, 2023 at 22:20
-1

While not built-in, 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.

1
  • 5
    This doesn’t answer the question: the OP is looking for the ability to edit the current command with the mouse (at minimum, place the cursor), which gpm doesn’t provide. Jun 21, 2022 at 8:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .