I would like to bind a key with bash / readline, to clear the bottom of my console screen.
The ANSI sequence to clear the bottom of the screen is \e[J
, so I tried to add the following line to my .inputrc
, but it doesn't work, it simply ignores the three chars:
Control-N: "\e[J"
If I add some test chars inside the string:
Control-N: "BEFORE \e[J AFTER"
, then the string BEFORE
is inserted and it stops there.
For the moment, I found this workaround, but it obviously displays a line with the echo
command, and I don't want it:
Control-N: "echo -ne \"\\e[J\"\n"
Is it possible to send ANSI sequences with a readline
binding?
Best Answer
Two parts:
echo
orprintf
.Key bindings for readline expect a single function-name or literal string. In your example, readline read what it considered a possible function name, and ignored the rest of the line.
So: no, bash/readline provide no useful features for echoing an escape sequence directly as a key-binding. You have to go another level, as noted, using
echo
.