Adding ANSI color escape sequences to a bash prompt results in bad cursor position when recalling/editing commands

前端 未结 1 1306
挽巷
挽巷 2020-12-16 14:31

If I set my command prompt like:

export PS1=\'\\033[0;33m[\\u@\\h \\w]\\$ \\033[00m\'

The color of the prompt will be yellow and everything

相关标签:
1条回答
  • 2020-12-16 15:04

    You need to enclose the non-printing characters in \[ ... \] so that bash knows to ignore them when computing the length of the prompt:

    export PS1='\[\033[0;33m\][\u@\h \w]\$ \[\033[00m\]'
    
    0 讨论(0)
提交回复
热议问题