Timeline for What color codes can I use in my Bash PS1 prompt?
Current License: CC BY-SA 3.0
30 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 25, 2023 at 14:53 | comment | added | goldilocks | Because up until some point after this was written, I was under the impression that $(()) is a bashism and not POSIX, and I use sh in the shebang. Which is not true (it does work in sh). That said, in the context here it seems like a completely irrelevant distinction; there's no performance angle. | |
| Jan 25, 2023 at 9:54 | comment | added | phuclv | why do you use bc instead of just echo $((16 + $1 * 36 + $2 * 6 + $3))? | |
| Nov 25, 2020 at 12:43 | comment | added | Marslo | thanks a lot! 38;5; helps me to setup 256 color PS1 | |
| Mar 21, 2018 at 19:30 | history | edited | goldilocks | CC BY-SA 3.0 | footnote |
| Feb 20, 2018 at 14:16 | comment | added | zeratul021 | Kudos for the escape sequence enclosing explanation. No more "weird things" while searching/navigating history. | |
| Feb 4, 2018 at 16:17 | history | edited | Jeff Schaller♦ | CC BY-SA 3.0 | added image title |
| Oct 7, 2016 at 13:24 | comment | added | Flimm | Let us continue this discussion in chat. | |
| Oct 7, 2016 at 13:22 | comment | added | goldilocks | @Flimm Also, a bit besides the point but with bash I'd use \d or \D{format} in a prompt, not $(date) (see PROMPTING in man bash). | |
| Oct 7, 2016 at 13:21 | history | edited | goldilocks | CC BY-SA 3.0 | added 481 characters in body |
| Oct 7, 2016 at 13:12 | comment | added | goldilocks | Fair enough, but the "execute this command every time" is a corner case that's not relevant to the actual question, which is about setting color in the prompt, and "\\" vs. '\' is a subjective and inconsequential difference, as is using different styles of quotes here (since I have to use double quotes for some of it), and arguably confusing. However, I'll add a note about using single quotes if you want the output of a command included (and to be a stickler, they aren't "exactly" the same -- double quotes are more efficient because the interpolation is done with the definition). | |
| Oct 7, 2016 at 13:03 | comment | added | Flimm | For your echo example, I would do export PS1='\033[01;32mBold green', which does display the result in green, I would not do export PS1="\\033[01;32mBold green", even though it has exactly the same effect, because now I have to use mental cycles converting the double-backslash into a normal backslash that the prompt uses. | |
| Oct 7, 2016 at 13:00 | comment | added | Flimm | That's the point, I don't want the variables to be interpolated, because they're going to be interpolated later. For example, export PS1='$(date)' works as intended, the prompt is always the current time, whereas export PS1="$(date)" the prompt is always the time it was when PS1 was set. | |
| Oct 7, 2016 at 12:59 | comment | added | goldilocks | That should have been =, not eq, sorry, but the point remains the same. | |
| Oct 7, 2016 at 12:53 | comment | added | goldilocks | @Flimm That would screw everything up, because the shell does not interpolate variables or escape sequences inside single quotes: foo=bar; echo "$foo" prints bar. But echo '$foo' prints $foo. Even worse, try echo -e '\\033[01;32mBold green'. And consider a test: if [ '$foo' eq bar ] could never be true, because '$foo' will always just be the literal string, and not the contents of the variable. | |
| Oct 7, 2016 at 12:49 | comment | added | Flimm | I wish you would use single quotes instead of double quotes throughout. | |
| Dec 5, 2014 at 22:00 | comment | added | Sopalajo de Arrierez | @MichaelPlotke, your link is dead. Could you please repost it? | |
| Dec 2, 2014 at 8:01 | comment | added | ocodo | Ahh, nice to see my color chart going to good use ;) | |
| Jul 3, 2014 at 3:13 | comment | added | Volker Siegel | colortest-256 list the xterm pallette in a nice compact form. (apt-get install colortest if missing) | |
| May 4, 2014 at 15:08 | comment | added | user3730 | Please, don't use echo for anything other than literal text that doesn't start with a dash (-). It's unportable. All common implementations violate the standard which states that no options should be supported. Worse, they're inconsistent. You should use printf instead. (And do not embed variables inside printf statements, use %s.) | |
| May 1, 2014 at 20:27 | comment | added | Michael Plotke | The color reference script found here might be more useful, being compact yet still having the codes and with each color separated for clarity. | |
| Apr 20, 2014 at 11:44 | vote | accept | Michael Durrant | ||
| Apr 14, 2014 at 17:25 | history | edited | goldilocks | CC BY-SA 3.0 | added 892 characters in body |
| Apr 13, 2014 at 11:58 | history | edited | goldilocks | CC BY-SA 3.0 | Added stuff about $TERM and setting 256 color prompt |
| Apr 12, 2014 at 19:08 | history | edited | phemmer | CC BY-SA 3.0 | remove accidental $ in export |
| Apr 12, 2014 at 17:05 | comment | added | goldilocks | @IBr Interesting point. Just viewing all the colors is a drop dead simple task, so I few lines of bash above to do this. | |
| Apr 12, 2014 at 17:03 | history | edited | goldilocks | CC BY-SA 3.0 | added 327 characters in body |
| Apr 12, 2014 at 16:52 | comment | added | IBr | I suggest for original asker to test color availability with a test chart. There is one here: robmeerman.co.uk/unix/… or it can be very easy to do one, if one does not trust shell scripts found on internet. | |
| Apr 12, 2014 at 16:15 | history | edited | goldilocks | CC BY-SA 3.0 | added 1096 characters in body |
| Apr 12, 2014 at 16:09 | history | edited | goldilocks | CC BY-SA 3.0 | added 1096 characters in body |
| Apr 12, 2014 at 15:50 | history | answered | goldilocks | CC BY-SA 3.0 |