I have played around with PS1 and PROMPT_COMMAND in bash to create a zsh-style right side prompt. I have a solution who almost works.
The problem is that if I write a long line of input, the second line overwrites the first one. The third line will appear nicely on a new line.
Maybe some line counter are of-by-one because my cursor movement, or is this a limitation/bug?
A simple example:
export PS1="prompt>[33[s33[10C]test[33[u]"
Print prompt>, save position, move 10 characters to the left, print test, restore position.
The prompts looks nice and works perfectly, until i write more then one line of text.
Example 1, expected behaviour:
------------------------------------ prompt> test prompt>ls test files... prompt>1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
Example 2, current behaviour:
------------------------------------ prompt> test prompt>ls test files... 14 15 16 17 18 19 20 21 22 23 24 253 26 27 28
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Ah, of course. Test should not be counted as a visible character and should be included between [ and ].
Working example:
export PS1="prompt>[33[s33[10Ctest33[u]"
The reason was because if bash count test as a visible character it will assume it’s left if the cursor and the calculation of available characters left on the current line will be off by four characters (length of ‘test’).
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0