0

I have tried a few variations to get bold yellow, see below.

export PS1="\[\e[1;33m\]\w\n\h:\u >\e[0m\]\]"

For some reason, if I have a sudo command in my bash history, say sudo chmod, every command before that becomse sudo ls, sudo cd, the "sudo" parts stays. It becomes part of the cursor/PS1?

Any information appreciated. Is there a different form for the above cursor?

Paul
  • 608
  • 1
  • 9
  • 23
  • 2
    You are failing to start a sequence of non-printing characters to account for the formatting clear sequence at the end of that prompt string. `\e[0m\]\]` You end a non-printing sequence twice (`\]`) but do not start one for the end sequence. – Etan Reisner Oct 27 '14 at 14:40
  • http://mywiki.wooledge.org/BashFAQ/053 – Etan Reisner Oct 27 '14 at 14:43
  • I attempted a few, that is just one of many. So what should it be? – Paul Oct 27 '14 at 14:44
  • The linked question and FAQ entry discuss this in some detail. But the short version is a pair of `\[` and `\]` around anything that isn't a printable character in the output. Like you have for the starting color formatting. – Etan Reisner Oct 27 '14 at 14:46
  • Got it. Still seems mystical. – Paul Oct 27 '14 at 14:50
  • It is a bit magical. It is even more magical once you learn that those aren't actually the magic characters themselves those are just placeholders and get translated to the *real* magic values later. =) – Etan Reisner Oct 27 '14 at 14:59
  • @EtanReisner: out of curiosity, what are the "real magic values" to which you refer? – rici Oct 27 '14 at 15:11
  • @rici `\001` and `\002`. – Etan Reisner Oct 27 '14 at 15:23
  • @EtanReisner: `RL_PROMPT_START_IGNORE` and `RL_PROMPT_START_IGNORE` aren't *that* magical, IMHO. The part of PS1 escape processing which is important is that prompt backslash expansion (including the ignore sequences) happens *before* command and parameter expansion, so perhaps it would have been more accurate to say "...translated to the *real* magic values earlier." In any case, there is certainly an (IN)FAQ here waiting to be answered. – rici Oct 27 '14 at 20:05
  • @rici I hadn't paid attention to evaluation order when I went digging to find out what they became internally (to use in my prompt). So that may very well be more accurate. My point was mostly just that the rabbit-hole continued (and that even finding out that details required/requires a good deal of digging or it did when I went looking). – Etan Reisner Oct 28 '14 at 01:24

0 Answers0