[arch-general] bash variable PS1 confuses the terminal somehow
13 PROMPT_COMMAND=' 14 if (($?)); then 15 warn="^[[31mWARNING^[[m" 16 else 17 warn= 18 fi 19 date=`date` 20 PS1="^[[s^[[$(($COLUMNS-28))C^[[0;33m$date^[[u^[[0;31m$warn^[[0;32m[^[[1;33m\u^[[0;32m@^[[1;36m\w^[[0;32m]\$^[[m" 21 ' i'm using this PROMPT_COMMAND to set PS1 everytime it is played, it seems to work perfectly except later i found a strange behavior of the terminal, both in xterm under X and agetty under the console. for example, when under the console, i found the terminal column indicated by the bash variable $COLUMNS is 160, however, when i type some command about 50 characters long, the line which i'm typing wraps to the begining, and destroys what i typed earlier, this makes typing long commands really difficult...and everything is just fine when i just set the PS1 variable to a very simple value without escape sequences. anyone knows how to fix this?
On Wed, Sep 28, 2011 at 9:22 AM, <bfsc.yb@gmail.com> wrote:
13 PROMPT_COMMAND=' 14 if (($?)); then 15 warn="^[[31mWARNING^[[m" 16 else 17 warn= 18 fi 19 date=`date` 20 PS1="^[[s^[[$(($COLUMNS-28))C^[[0;33m$date^[[u^[[0;31m$warn^[[0;32m[^[[1;33m\u^[[0;32m@^[[1;36m\w^[[0;32m]\$^[[m" 21 '
i'm using this PROMPT_COMMAND to set PS1 everytime it is played, it seems to work perfectly except later i found a strange behavior of the terminal, both in xterm under X and agetty under the console. for example, when under the console, i found the terminal column indicated by the bash variable $COLUMNS is 160, however, when i type some command about 50 characters long, the line which i'm typing wraps to the begining, and destroys what i typed earlier, this makes typing long commands really difficult...and everything is just fine when i just set the PS1 variable to a very simple value without escape sequences. anyone knows how to fix this?
Put \[ and \] around all the sections that don't actually print things to the terminal, so bash knows not to count them when determining how long the prompt is.
13 PROMPT_COMMAND=' 14 if (($?)); then 15 warn="^[[31mWARNING^[[m" 16 else 17 warn= 18 fi 19 date=`date` 20 PS1="\[^[[s\]\[^[[$(($COLUMNS-28))C\]\[^[[0;33m$date\]\[^[[u\]\[^[[0;31m$warn\]\[^[[0;32m[\]\[^[[1;33m\u\]\[^[[0;32m@\]\[^[[1;36m\w\]\[^[[0;32m]\$\] 21 ' i changed PROMPT_COMMAND to this as you said, it fixes what i mentioned earlier, but produces more problem, like when i type one character and then use BACKSPACE to delete it, the entire promt is gone, and again bring me to the begining of the line, also when i use ^R to search for history command, the prompt is destroyed too...
On Wed, Sep 28, 2011 at 9:46 AM, 清显 <bfsc.yb@gmail.com> wrote:
13 PROMPT_COMMAND=' 14 if (($?)); then 15 warn="^[[31mWARNING^[[m" 16 else 17 warn= 18 fi 19 date=`date` 20 PS1="\[^[[s\]\[^[[$(($COLUMNS-28))C\]\[^[[0;33m$date\]\[^[[u\]\[^[[0;31m$warn\]\[^[[0;32m[\]\[^[[1;33m\u\]\[^[[0;32m@\]\[^[[1;36m\w\]\[^[[0;32m]\$\] 21 '
i changed PROMPT_COMMAND to this as you said, it fixes what i mentioned earlier, but produces more problem, like when i type one character and then use BACKSPACE to delete it, the entire promt is gone, and again bring me to the begining of the line, also when i use ^R to search for history command, the prompt is destroyed too...
I do something similar, but I don't change PS1 in the prompt command. My prompt does end up on two lines, but when I'm in a long path at least the command edit area stays large. PS1='\[\e[1;32m\]\u\[\e[1;33m\]@\h\[\e[0m\] \$ ' PROMPT_COMMAND='echo -e "\e[1;36m$(date "+%a %d%b%y %H:%M:%S") \e[1;33m${PWD/${HOME}/~}\e[0m"
yeah, you are right, i didn't do what you say correctly earlier, now everything is right. thanks!
participants (4)
-
bfsc.yb@gmail.com
-
Dwight Schauer
-
Ray Kohler
-
清显