开发者

Rlwrap doesn't seem to cooperate with "read -e"

A new twist to somewhat common question:

In my interactive script I pre-fill the user input like so:

#process_line.sh

INPUT=$1 # previous value
read -e -p "> " -i "$INPUT" INPUT

To implement command history I call process_line.sh

    rlwrap ./process_line.sh $INPUT

Now here's the twist: if I have the "read -e" option, I can edit the pre-filled input BUT there is no command history, and adversely, I can have command history, courtesy of rlwrap , without the "read -e" option, but no pre-filling (that is, "read -i"开发者_StackOverflow doesn't really do anything).

The question, of course, is whether I can have both input pre-fill and editing AND command history at the same time.

Thanks!


Turn off the -e to read. Then the two readline implementations won't clash.

To get the prompt, you can pass -S "> " to rlwrap.


This use case has been in the rlwrap manual from version 0.25 onwards; how exactly to go about it depends a bit on the rlwrap version.

In rlwrap 0.37 you do it like this:

INPUT=$(rlwrap -o -S ">" -P $INPUT cat)

The advantage of this approach is that every input variable can be given its own history and completion list (using the -f and -H options)

The cygwin version (0.24) is indeed ancient, but compiling rlwrap yourself should be painless. If you want to you can build a statically linked version (see the INSTALL file for instructions) and distribute it along with your script.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜