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

后端 未结 3 1857
[愿得一人]
[愿得一人] 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:05

    http://mywiki.wooledge.org/BashFAQ/053 -- I have a fancy prompt with colors, and now bash doesn't seem to know how wide my terminal is. Lines wrap around incorrectly.

    By the way; for your reference; here's my PS1 which looks like this:
    (source: lyndir.com)

    \[$reset$bold$green\]\u@\h\[$blue\] \W \[$red\]${?/#0/\[$green\]}\$\[$reset\]
    

    Notice how I put all the color codes in $parameters to make it neater, but more importantly, because you should be using tput to generate them. See:

    http://mywiki.wooledge.org/BashFAQ/037 -- How can I print text in various colors?

    I declare my color parameters in a utility script that gets sourced by my ~/.bashrc (and any scripts I write) which is called bashlib.

    On a final note; put your PS1 definition in ~/.bashrc and don't export it. There's absolutely no reason why you should add your PS1 definition to the environment of any and all processes you spawn from your shell.

提交回复
热议问题