mcfly
mcfly copied to clipboard
Multiline commands are sometimes split in bash history.
Multiline commands are sometimes split in bash history.
Pasting this in the terminal and then pasting the following:
some_function () {
printf '1\t2\t3\n' \
| awk -F '\t' '
{
print $1;
print $2;
print $3;
}' \
| cat
}
In bash without mcfly, pressing the up key, will bring back this full entry (history command):
2006 some_function () { printf '1\t2\t3\n' | awk -F '\t' '
{
print $1;
print $2;
print $3;
}' | cat ; }
With mcfly, this entry is splitted:
1340 some_function () { printf '1\t2\t3\n' | awk -F '\t' '
1341 {
1342 print $1;
1343 print $2;
1344 print $3;
1345 }' | cat ; }
That does sound like a real bug, thank you for reporting it.
Are you sure that the normal bash history works correctly with multiline commands? When I try your example without mcfly, it works in the local session, but if I start a new session, it shows up as separate lines in history.
Apparently rereading history from bash history does not preserve multiline commands: https://lists.gnu.org/archive/html/bug-bash/2011-02/msg00029.html. It is a pity as I use multiline command quite often.
I see this is tagged wontfix. Would you be willing to merge a pull request for this?
Sure, if you can find a solution! I'm not sure how you can fix it. Bash history without timestamps doesn't differentiate single and multiline, or does it?
Once the history is written with history -a then the information is lost, but history 1 is reliably parseable. You'd need to restructure a bit and pipe it into the mcfly binary for parsing, maybe HISTTIMEFORMAT="%s " history 1 | mcfly record_history bash or something.
Doesn't presence of a backslash at the end indicate multi-line?
Multiline commands can also be started from unclosed quotes or parens. I would hope to avoid trying to parse bash commands to see which are part of a multi-line command, as that would be shell & version specific, and hard to get perfect.
If you can get it working, I'm very open to a PR.