Reputation: 33
When editing PS1, one using escape sequences can manipulate the form of the prompt in almost anyway. Howver what holds true every time is that stdout starts right after the command input. For for simplicity's sake, here's an example of a simple prompt that adds some elements below the command entry:
PS1='aaaaaaaa\n\[\033[1B\]bbbbbbbb\n\[\033[2A\]\u@\h:\w\$ '
that looks more or less like this:
aaaaaaaa
user@hostname:~$ █
bbbbbbbb
Notice the position of the cursor once the drawing of the prompt is finished. The \033[
used in the PS1 variable manipulate the cursor (moving it up and down) to be able to draw the 'b' separator below the prompt and return to position.
If however a command is run, stdout as expected overwrites whatever is below the command:
aaaaaaaa
user@hostname:~$ echo 'hello '
hello bb
aaaaaaaa
user@hostname:~$ █
bbbbbbbb
The question is whether there is a way to manipulate the behavior of the prompt from the point of the command's last character in the following fachion:
<editable prompt><command><editable area after command?>
If for example I could instruct bash to print a newline or any escape sequence after every command that would solve the problem portrayed by the example.
Upvotes: 3
Views: 187
Reputation: 6742
This trick might work. I got the idea from https://superuser.com/questions/175799/does-bash-have-a-hook-that-is-run-before-executing-a-command but I simplified as much as I could.
trap 'echo' DEBUG
The theory is simply to use bash's DEBUG trap to write a blank line before executing anything.
Upvotes: 3