I am having a weird issue with my terminal wrapping, and after reading online I have found out it is likely because of my PS1 setup, however, I looked at it, and it seems to match what people are saying, so I am not sure whether or not I am doing something else wrong.


Anyone to possibly identify what might be wrong?

One way I tried to combat this was to set stty columns to 1000 but that made a lot of other things worst (such as ls and vim).

  • PS1 is related to your prompt. TERM is your terminal setting. Your PS1 works fine for me but I did notice you're using ANSI escape codes for coloring. Are you using TERM=ansi? – jbrahy Mar 11 '15 at 4:57

Editing to Clarify: I have seen issues like this in the past due to incorrect escaping of non printed colors. In my case it was due to not having \[ in front of each escape sequence in your case it may be more to do with not recognizing '\e' so i would recommend replacing \e with \033 making sure that you always have [\033 in front of each [x;yzm] for your colors. I presume \e[m\] is meant to disable colors, I would use"\[\033[0m\]" for this instead (mostly because i know it works in all cases) You may consider setting this as a variable in the same way i have below with PMT_Color_Off to tidy up your prompt and make it easier to debug. I have shown examples of what i do below.

I am escaping my colors like so PMT_Red="\[\033[0;31m\]" where as for non prompt it is just Red="\033[0;31m"

To turn the color off I use PMT_Color_Off="\[\033[0m\]" and Color_Off="\033[0m" for non prompt

a working copy of the prompt on one of my development machines is

export PS1="\[\033[01;33m\]$(ifconfig | grep "inet" | grep -v "" | awk '{print $2}' | awk -F: '{print $2}') \[\033[01;32m\]\u@\h \[\033[01;34m\]\[\033[01;33m\]\w #\[\033[00m\] "

http://www.askapache.com/linux/bash-power-prompt.html also uses the \033 escape rather then \e

I have tested mine on several terminal emulators including xterm, gnome-terminal, terminology and the frame buffer

|improve this answer|||||
  • This doesn't really answer the question... – jasonwryan Mar 11 '15 at 5:52
  • Added a section at the top to clarify that your issue is related to escaping / unknown characters before putting the way i fix it – simotek Mar 11 '15 at 6:09

Make sure all non-printable bytes in your PS1 are contained within \[ \]. This is because bash counts the length of them in the total length of your prompt unless they are properly "escaped". Bash then uses the length of the prompt to determine when it needs to wrap the line. I think this is what is causing the issue of the weird line wrap on overly long commands.

I was also able to find another stack exchange HERE that may be of use.

|improve this answer|||||
  • Also have you tried editing your .bashrc file to include COLUMNS=250 – Dylan Mar 11 '15 at 5:16
  • I tried that, it did not help. I read a similar post on here that mentioned that, and one other one. setting columns to 250 did nothing, and the other was something like ssts colums to 1000, which made everything worst... – Mallachar Mar 11 '15 at 6:35
  • I assume that after you edited your .bashrc file you restarted or logged out and back in? Hmmm, Have you tried resetting your PS1 back to a deafult setting and tried an overly long command to ensure there is nothing else impacting your shell? For example try entering PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$' and then try a super long command and make sure it doesn't overwrite your command prompt. – Dylan Mar 11 '15 at 6:40
  • Yes, when I remove the entire PS1 it goes back to normal and works fine. Seems limited to what ever the PS1 issue is. And after every edit I would do a source ~/.bashrc and would restart the terminal. That is how I noticed it caused issues with VIM, when I tried to re-edit it, it caused issues. Had to use nano to fix it. – Mallachar Mar 11 '15 at 8:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.