Why is this bash prompt acting strangely/disappearing, and how do I fix it (OS X)?

后端 未结 3 1852
[愿得一人]
[愿得一人] 2020-12-05 05:48

I admit that I use a somewhat long-winded bash prompt:

--(username)-(Wed April 01|12:00:00)--(~ $

Recently, I got the bright idea to change

3条回答
  •  时光取名叫无心
    2020-12-05 06:03

    It sounds like this should solve your problem.

    This seems to work for me*:

    export PS1='--(\[\e[$((32-${?}))m\]\u\[\e[0m\])-(\[\e[$((32-${?}))m\]\d\[\e[0m\]|\[\e[$((32-${?}))m\]\T\[\e[0m\])--(\[\e[$((32-${?}))m\]\w\[\e[0m\] \$ '
    

    * well, really export PS1='\u@\h:\w\$ ' works for me

    To quote the linked post, the answer lies in adding \[ and \] around all of your color sequences in your PS1 declaration:

    Before I had the following value for PS1:

    '\e[0;34m\h:\w [!]\$\e[0m '

    which gave me a nice blue prompt of the following form

    hostname:working-directory [command-number]$

    However, I had the same line-wrapping problem you did. The fix was to insert \[ and \] around the ANSI escapes so that the shell knows not to include them in the line wrapping calculation. This results in the following value for PS1:

    '\[\e[0;34m\]\h:\w [!]\$\[\e[m\] '

提交回复
热议问题