2

I would like the CasebashMac:bfgenv chris$ part of the following line to appear in a different color in my terminal.

CasebashMac:bfgenv chris$ python
Casebash
  • 4,393

2 Answers2

8

I set the PS1 variable in my .bashrc to achieve this.

  • Open Terminal
  • [editorofchoice] ~/.bashrc
  • Add a line with the following:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

  • Save the .bashrc
  • Exit Terminal and re-open. You should now have a green prompt.
BinaryMisfit
  • 6,515
  • 4
  • 35
  • 49
  • 1
    Where is this bashrc file? – Casebash Oct 17 '10 at 00:45
  • 1
    @Casebash It should be in you home folder for your user account. If it does not exist, which often it doesn't, just create it. – BinaryMisfit Oct 17 '10 at 08:43
  • 1
    “.bashrc” won’t be there by default, and since it has a DOT, you won’t see it in finder (unless you have told it to show invisible files). Therefore it’s usually safe to use “vi” or “pico" to edit the file, because if it doesn’t exist, it will create it. – Martin Marconcini Oct 17 '10 at 14:02
  • It works if I run the command using export, but not in my .bashrc file. CasebashMac:~ chris$ cat ~/.bashrc PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' – Casebash Oct 17 '10 at 20:04
  • @Casebash. I am not sure what he problem is. I copied that straight out of the .bashrc on my machine. The actual PS1 line I got from my Ubuntu Server since I wanted both to be the same. Also make sure you exit both the terminal and quit terminal and then reopen. – BinaryMisfit Oct 18 '10 at 09:07
  • @Diago: Maybe there is another config file somewhere with higher priority? – Casebash Oct 18 '10 at 22:18
  • @Casebash. Doubt it. All customizations I have done to the terminal and my profile has always been in .bashrc. I have double checked on my side and it is correct. I am not very clued up on how it works, I really just applied what I know about Linux to get it to work for me since the rules are the same. I am not sure why it's not working in your case. – BinaryMisfit Oct 19 '10 at 07:01
  • There is why this works (an explanation about the values that go on PS1): http://osxdaily.com/2006/12/11/how-to-customize-your-terminal-prompt/ – Maic López Sáenz Dec 16 '11 at 23:09
2

The terminal app does not actually change the colours, this is controlled by the shell that is being run. The default shell is bash and controlling colours is done by altering the prompt. There are many tutorials and other documents on the web to tell you more.

One guide to customising the prompt is from IBM

mmmmmm
  • 30,160
  • Please include an example directly into your answer. – nohillside Jan 16 '19 at 23:46
  • @Hillside - not really as I think too broad for an answer – mmmmmm Jan 16 '19 at 23:48
  • @nohillside but then again see my answer here https://apple.stackexchange.com/questions/59480/how-to-change-the-color-and-format-of-the-static-host-path-user-string-in-the-te?rq=1 - OK we have a duplicate - my answer there is much better than here and the the answer here is not that good. Close this as a duplicate? – mmmmmm Jan 16 '19 at 23:58