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

marked as duplicate by nohillside terminal Jan 17 at 5:45

This question was marked as an exact duplicate of an existing question.

5

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.
  • 1
    Where is this bashrc file? – Casebash Oct 17 '10 at 0: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 8: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 9:07
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

  • Please include an example directly into your answer. – nohillside Jan 16 at 23:46
  • @Hillside - not really as I think too broad for an answer – user151019 Jan 16 at 23:48
  • @nohillside but then again see my answer here apple.stackexchange.com/questions/59480/… - 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? – user151019 Jan 16 at 23:58

Not the answer you're looking for? Browse other questions tagged .