0

The line wrap is working weirdly when I use the following PS1:

export PS1="\[\033[00;32m\][\d \T] \[\033[0;31m\]\u@\H:\[\033[0;37m\]\w\[$(tput sgr0)\] \n\[\033[0m\]$ "

It is line wrapping onto the same line. That too within 80 characters when my terminal supports way more than that on a single line.

  • 1
    line wrapping going wrong is usually a symptom of the shell counting the prompt length wrong, usually if the non-printing parts aren't wrapped in \[ .. \]. But here they seem to be. And I can't even replicate the problem with the prompt you had in the question source (the way it looked in the question in the original version was wrong, the post formatting ate backslashes from the \[ escapes) – ilkkachu Mar 12 at 16:18
  • Just curious: why use [00;32m instead of $(tput setaf 2)? Sometimes, people avoid calling tput because they don't want it to be invoked each time the prompt is generated, but the way you've constructed your assignment it would only be called when PS1 is initially assigned, so falling back on the explicit assignment seems to have no benefit. – William Pursell Mar 12 at 16:36
  • @WilliamPursell I copy pasted the segements from random sites I found using Google search :) I have no clue what any of this means. – Aditya Mar 12 at 16:37
  • @ilkkachu, so this is on my work pc. I am guessing that when they created my account they might have put some PS1 variable or some thing else that might create a problem in a different RC file. Right now I am looking at ~/.bashrc. Are there any other files I should check for conflicts? – Aditya Mar 12 at 16:39
  • @Aditya, well, you need to look at the value that PS1 finally gets set to. That's often ~/.bashrc, but I set mine in ~/.profile. You can use printf "%s\n" "$PS1" to see the value PS1 actually has. (Or just put PS1='foo$ ' in your .bashrc, and see if it sticks. If not, then some other file sets it.) Bash's setup of startup files is a bit complicated and more so since often some of the files are made to call other files. – ilkkachu Mar 12 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.