-2

I would like to invoke my own command line editor in bash or zsh when Alt+Enter is being pressed. It should do some editing and submit result to the shell on Enter. So basically my editor takes current command line content and returns a modified one. Any ideas how to approach integration? I do know how to work with ANSI terminals, just wondering how to integrate my editor console app to the shell in this way.

Dmitry Nogin
  • 3,670
  • 1
  • 19
  • 35
  • 1
    The bash builtin `bind` should give you everything you need. But it seems that (using vi key bindings), `v` pretty much does what you want, opening the current command line in $EDITOR. – William Pursell Jul 21 '20 at 19:16

2 Answers2

1

For Bash:

There is a Readline command that opens the current command in an editor, edit-and-execute-command. By default, it is bound to C-x C-e, and it opens the command in what $VISUAL is set to, or $EDITOR, or with Emacs.

You can set $VISUAL to your editor by exporting it into the environment, for example in ~/.bashrc:

export VISUAL=youreditor

and bind it to Alt+Enter with

bind '"\e\C-m": edit-and-execute-command'

on the command line, or

"\e\C-m": edit-and-execute-command

in ~/.inputrc.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
1

Almost the same for zsh:

  export VISUAL=youreditor
  autoload -Uz edit-command-line
  zle -N edit-command-line
  bindkey '\e\C-m' edit-command-line
okapi
  • 1,340
  • 9
  • 17