geerlingguy / dotfiles

My configuration. Minimalist, but helps save a few thousand keystrokes a day.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bash PS1 variable issues

jrgoldfinemiddleton opened this issue · comments

export PS1="\[\e[0;32m\]\]\[\] \[\e[1;32m\]\]\t \[\e[0;2m\]\]\w \[\e[0m\]\]\[$\] "

Hi @geerlingguy, was using your PS1 variable for my prompt on macOS High Sierra via iTerm and having no issues but recently I upgraded Bash to version 5.0 using Homebrew and discovered issues with my prompt. If I typed a command that extended to the far right end of the line, additional characters were placed at the start of the same line, overwriting the line rather than jumping to the next one. By making some tweaks to your PS1 variable I was able to resolve that issue. Here is what I came up with:

export PS1="\[\e[0;32m\] \[\e[1;32m\]\t \[\e[0;2m\]\w \[\e[0m\]\$ "

I noticed you had an extraneous \] sequence after each color code (in addition to the correct escape wrapper). Also the and $ were unnecessarily marked as non-printable characters, which caused my ctrl-a presses to move the cursor back onto the $ rather than two positions after it.

Not sure why the bug wasn't showing up with the default Bash install but you can try to reproduce the issue by installing a different version of Bash.

Yikes, right you are! And that fixed a little bug that I sometimes ran into, where copying and pasting multiline commands would break them to newlines instead of copying one command.

Thanks for this :)