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.
问问题
95 次
2 回答
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
.
于 2020-07-21T19:23:26.303 回答
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
于 2020-07-23T17:30:46.060 回答