OS X Terminal text stacking on top of itself

后端 未结 6 1868
夕颜
夕颜 2020-12-24 05:14

I\'m encountering a strange issue in the Terminal app in Mac OS X Lion. When I enter in a long line of text that should wrap to the next line when it reaches the edge of the

6条回答
  •  甜味超标
    2020-12-24 06:00

    PS1 environment variable determines what shell's prompt will look like. man bash gives full documentation on it. (There are actually several of them, for different modes).

    There are number of files that may be setting it, usually one of ~/.profile, ~/.bashrc, /etc/profile or /etc/bashrc.

    If you're going to have color codes or other control sequences inside it, you must wrap them with \[ and \] properly (and NOT wrap normal text), otherwise line editing may become messed up like in your case. I suggest resetting PS1 to the default value then carefully adding coloring back item by item.

    For example:

    PS1='\[\033[1m\033[32m\]\u@\h \w\[\033[0m\]\$ '
           ^^^^^^^^^^^^^^^            ^^^^^^^
    

    Coloring commands are underlined. Note how they are surrounded with \[ \].

提交回复
热议问题