一次滚动整个多行命令的 Readline 类型包装器
Readline type wrapper that scrolls entire multiline commands at one time
我正在使用增强的 kotlin
REPL 并输入了多行代码片段:
$rlwrap bin/ki.sh
ki-shell 0.3/1.4.21
type :h for help
[0] fun reformat(
str: String,
normalizeCase: Boolean = true,
upperCaseFirstLetter: Boolean = true,
divideByCamelHumps: Boolean = false,
wordSeparator: Char = ' ',
)
{
println("In reformat")
}
如果您细心的话,您可能已经注意到 kotlin shell 已被 rlwrap
“包裹”。我曾希望能提供一次击键来滚动浏览该多行命令。然而,从下面的屏幕截图中可以看出,向上箭头键(同样是 shift- 或 option- 或 command- 或 control- 向上箭头)一次只能向上移动一行
那么是否有任何类似 REPL 的实用程序的包装器可以启用多行滚动?
请注意,在某些情况下,scala
REPL 确实像 ipython
一样具有多行滚动(在我的情况下,仅在 iTerm
下,但在 Terminal
下没有).
我在 macOS Catalina
但希望答案同样适用于大多数 *NIX 变体。
来自 rlwrap
手册:
-m, --multi-line [newline_substitute]
Enable multi-line input using a "newline substitute" character
sequence (" \ ", [space-backslash-space] by default). Newline sub‐
stitutes are translated to newlines before sending the input to
command. With this option, you can call an external editor
$RLWRAP_EDITOR on the (expanded) current input with the
rlwrap_call_editor key (CTRL-^ by default)
使用 rlwrap -m
时,按 CTRL+^ 会将您带到一个编辑器,您可以在其中编辑多行代码段。退出编辑器后,该片段将被发送到 rlwrap
ped 命令,并作为 one 单行(替换换行符)放入 rlwrap
历史记录通过“换行替换”)使用 ↑ 和 ↓ 浏览历史仍会将这些片段显示为 one 单行,但您可以在编辑器中随时将它们扩展为多行文本,方法是再次按 CTRL+^
不完全您要查找的内容,但确实一次滚动整个多行命令,我更喜欢例如ipython
你仍然(至少在我使用的终端上)必须按几次 ↑ 才能通过一个大的函数定义。
当然,与任何 readline 包装器一样,也有缺点:您将 lose 您的 CLI 可能具有的任何上下文相关的完成,甚至微不足道的 rlwrap
完成机制也将不起作用在多行编辑器中。
设置:
只需发出
即可“开箱即用”
$ rlwrap -m -a <my_cli_command> # -a because your cli probably
# does some line editing already
一些调整:
- 如果您喜欢不同的编辑器,请添加一行
export RLWRAP_EDITOR='<my_editor_of_choice>[-opts]
在你的 .bashrc
中。默认值为 vi +%L
。 %F
、%L
和 %C
in RLWRAP_EDITOR
将分别替换为文件名、行和列,以便在光标所在的位置进入编辑器在 rlwrap
- 要使用不同的编辑热键,请在
~/.inputrc
中添加类似 "\C-b":rlwrap-call-editor
的行(默认为 CTRL+^)
- 要使用不同的“换行符”(例如“||”),请向
-m
添加一个参数,如 rlwrap -m'||'
(默认为 ' \ '
)
- 如果您的
editor_of_choice
根据文件扩展名进行语法着色,请添加参数 -M.ext
(默认:无扩展名)
例如:
export RLWRAP_EDITOR='my_edit --auto-save-on-exit %F:%L'
# ... or put the above in .bashrc
rlwrap -a -m': ' -M_bas QLSuperBasic # ... those were the days
我正在使用增强的 kotlin
REPL 并输入了多行代码片段:
$rlwrap bin/ki.sh
ki-shell 0.3/1.4.21
type :h for help
[0] fun reformat(
str: String,
normalizeCase: Boolean = true,
upperCaseFirstLetter: Boolean = true,
divideByCamelHumps: Boolean = false,
wordSeparator: Char = ' ',
)
{
println("In reformat")
}
如果您细心的话,您可能已经注意到 kotlin shell 已被 rlwrap
“包裹”。我曾希望能提供一次击键来滚动浏览该多行命令。然而,从下面的屏幕截图中可以看出,向上箭头键(同样是 shift- 或 option- 或 command- 或 control- 向上箭头)一次只能向上移动一行
那么是否有任何类似 REPL 的实用程序的包装器可以启用多行滚动?
请注意,在某些情况下,scala
REPL 确实像 ipython
一样具有多行滚动(在我的情况下,仅在 iTerm
下,但在 Terminal
下没有).
我在 macOS Catalina
但希望答案同样适用于大多数 *NIX 变体。
来自 rlwrap
手册:
-m, --multi-line [newline_substitute]
Enable multi-line input using a "newline substitute" character
sequence (" \ ", [space-backslash-space] by default). Newline sub‐
stitutes are translated to newlines before sending the input to
command. With this option, you can call an external editor
$RLWRAP_EDITOR on the (expanded) current input with the
rlwrap_call_editor key (CTRL-^ by default)
使用 rlwrap -m
时,按 CTRL+^ 会将您带到一个编辑器,您可以在其中编辑多行代码段。退出编辑器后,该片段将被发送到 rlwrap
ped 命令,并作为 one 单行(替换换行符)放入 rlwrap
历史记录通过“换行替换”)使用 ↑ 和 ↓ 浏览历史仍会将这些片段显示为 one 单行,但您可以在编辑器中随时将它们扩展为多行文本,方法是再次按 CTRL+^
不完全您要查找的内容,但确实一次滚动整个多行命令,我更喜欢例如ipython
你仍然(至少在我使用的终端上)必须按几次 ↑ 才能通过一个大的函数定义。
当然,与任何 readline 包装器一样,也有缺点:您将 lose 您的 CLI 可能具有的任何上下文相关的完成,甚至微不足道的 rlwrap
完成机制也将不起作用在多行编辑器中。
设置:
只需发出
即可“开箱即用”$ rlwrap -m -a <my_cli_command> # -a because your cli probably
# does some line editing already
一些调整:
- 如果您喜欢不同的编辑器,请添加一行
export RLWRAP_EDITOR='<my_editor_of_choice>[-opts]
在你的.bashrc
中。默认值为vi +%L
。%F
、%L
和%C
inRLWRAP_EDITOR
将分别替换为文件名、行和列,以便在光标所在的位置进入编辑器在rlwrap
- 要使用不同的编辑热键,请在
~/.inputrc
中添加类似"\C-b":rlwrap-call-editor
的行(默认为 CTRL+^) - 要使用不同的“换行符”(例如“||”),请向
-m
添加一个参数,如rlwrap -m'||'
(默认为' \ '
) - 如果您的
editor_of_choice
根据文件扩展名进行语法着色,请添加参数-M.ext
(默认:无扩展名)
例如:
export RLWRAP_EDITOR='my_edit --auto-save-on-exit %F:%L'
# ... or put the above in .bashrc
rlwrap -a -m': ' -M_bas QLSuperBasic # ... those were the days