Search code examples
bashterminalls

Changing Color of Linux Terminal Directory shown on command line


I am trying to customize my terminal colors on my Macbook Pro. Using the Terminal app I adjusted my preferences for background color, text, and I made changes to the ANSI colors. I also specify export CLICOLOR=1 and export LSCOLORS=GxFxCxDxBxegedabagacad for the ANSI colors in my ~/.bash_profile file and then source it. When I use the ls command it lists the directories in the correct color that I wanted (blue, as seen in the picture). However, if I cd into a directory the directory path on the command line is not one of my specified ANSI colors (it's purple, as seen in the picture). Is there something else I need to make a change to in order to change that color setting to be the same blue that is used for ls? I do not know very much about bash and ANSI colors, so I apologize if I incorrectly used certain terminology. Terminal Example Picture Here
ANSI Color Settings Here


Solution

  • However, if I cd into a directory the directory path on the command line is not one of my specified ANSI colors (it's purple, as seen in the picture).

    The command line prompt does not care about LSCOLORS, its look is defined by variable PS1. To get your current PS1 value, use:

    declare -p PS1
    

    Mine looks like this (yours might differ):

    declare -- PS1="\\[\\e]0;\\u@\\h:\\w\\a\\]\\[\\e[1;32m\\]\\u@\\h\\[\\e[1;34m\\] [\\w] \\\$\\[\\e[0m\\] "
    

    To change the color of the directory part, modify the escape sequence right before [\\w], e.g. change \\[\\e[1;34m\\] to \\[\\e[1;33m\\] for yellow.

    To make changes permanent, add the new PS1 setting to your .bash_profile as well.