Is there's a way to update READLINE_LINE while running a command, and update it again when the command is complete?
Looking at Bash builtins docs:
-x keyseq:shell-command
Cause shell-command to be executed whenever keyseq is entered. When shell-command is executed, the shell sets the READLINE_LINE variable to the contents of the Readline line buffer and the READLINE_POINT and READLINE_MARK variables to the current location of the insertion point and the saved insertion point (the mark), respectively. If the executed command changes the value of any of READLINE_LINE, READLINE_POINT, or READLINE_MARK, those new values will be reflected in the editing state.
It's not very explicit, perhaps it means that the prompt is updated only once, after the shell-command is complete?
For instance, if I add this to .bashrc
bind -x '"\C-g":foobar'
foobar()
{
READLINE_LINE="# working on it..."
sleep 10
READLINE_LINE="# foo bar done"
}
when I press Ctrl-g
, whatever typed disappears, leaving the prompt empty for 10 seconds, until it shows # foo bar done
. The terminal never shows # working on it...
. (Bash 5.1, tested on ubuntu and macos).
Any suggestion about changing the prompt multiple times, e.g. to show some progress in case the command takes long?