When executing shell commands bound to key sequences with bind -x, the
initial line(s) of multiple line shell prompts and/or commands are left
intact; when the prompt is redisplayed, the initial line(s) are output
again, causing the appearance of duplicate lines. This seems to be due to
the code to clear the current (last) line in bash_execute_unix_command in
bashline.c, which also seems to be the only place where the line is
cleared in this fashion.
A minimal test case:
do_nothing () { :; }
bind -x '"\C-k": do_nothing'
Then compare the result of pressing C-k at the prompt when PS1 expands to
a single line vs. multiple lines, like '\u$ ' and '\u\n$ ' . The same
thing happens with input lines long enough to wrap, and at least there is
inconsistent with other actions that clear the input line.
I've confirmed this with 4.3.11(7)-release built from git commit b7ec181
(current as of this writing), as well as several patch levels of 4.2 as
shipped by various Linux distributions.
Does readline know enough about where a multi-line prompt starts to be
able to clear and redisplay the whole thing? I'm not familiar with the
code, but from a quick read it seems like that capability would be
necessary to change this behavior. I'm curious about this because I'm
looking for ways to do more advanced command rewriting than completion
permits, and the READLINE_LINE facility has some potential...
-Rob