3

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.

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

question above expanded to include .tcsh for the sake of completeness, fyi
@TrentHawkins if you have a separate, followup question please post a separate question, rather than changing one you already posted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.