Bash – Mouse click integration with SSH client, on command line, not just vim

bashmouseterminal

In vim, you can use the option :set mouse=a, and then (if your SSH client supports it) you will be able to simply click and the cursor will move, rather than having to use the arrow keys or whatnot.

I realize that vim switches to the 'alternate screen'. I'm just wondering if there's a way to use such integration on the 'main' screen also. If so, are there any shell script interpreters that handle this?

Right now I'm using bash, and sometimes I type a quite long command, and have to correct something mid-way through. If there was an alternative to bash which was reasonable, or an extension to bash which handles mouse interaction I would be pleased. Do you know what I need to make this work?

Further I'm interested in mysql but let's start with the main command line.

Best Answer

bash has the built-in ability to call an external editor to edit the current command line you're working on. Mouse support depends on the editor used.

If you're using bash's emacs-like mode, use Ctrl-XCtrl-E to access the editor.

If you're using vi-like keybindings, use ESCv

You can also use the built-in fc command to edit any previous line.

$ help fc

fc: fc [-e ename] [-lnr] [first] [last] or fc -s [pat=rep] [command]

Display or execute commands from the history list.

fc is used to list or edit and re-execute commands from the history list. FIRST and LAST can be numbers specifying the range, or FIRST can be a string, which means the most recent command beginning with that string.

Options: -e ENAME select which editor to use. Default is $FCEDIT, then $EDITOR, then vi

[...]


BTW, one small annoyance with this (in any of its forms):

There may be some simple way to abort an edit or to make bash return to editing the line itself and NOT execute it immediately, but I've never found one (I haven't looked very hard).

Quit-without-saving just executes the line as it was before you called the editor.

The only way I've found is to delete the entire buffer in the editor, then save and exit. Or add a # comment at the beginning, of course.

PS: I use emacs-mode line editing and Ctrl-XCtrl-E for vim when i need real editing power. I don't know why, I love vi and vim, but I just don't like vi-mode on the command line.

Related Question