Terminal Bash Command Line & Colors

Software developers spend a significant amount of time in Terminal (i.e. file systeming, giting, bash scripting).

The default mostly-white wall of text can be hard on the eyes and actually kind of difficult to read. Wouldn’t it be nice if you could more clearly view the terminal logs?

YES, so let’s make some changes that will increase producitivity and asthetics at the same time!

Customizing Your Bash Profile

First, you need to learn a little about bash. Bash is a Unix shell and command language and it is what you see when you load Terminal on your Mac. We will be customizing your bash Profile.

The first step is to go to start Terminal, navigate to your home directory, and open .bash_profile in a text editor.

terminal
1
2
3
4
//navigate to home directory and
//open .bash_profile in a text editor (i.e. sublime)
cd ~
sublime .bash_profile

Second, you can customize the bash prompt to show full filepath, hide username, and show your current git branch name (if applicable). We also add a new line to seperate the prompt from the prior command.

.bash_profile
1
2
3
4
5
6
7
#Git branch in prompt.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
#custom bash prompt
export PS1="\n\w\ $(parse_git_branch) "

Next, you can customize colors to better differentiate different bash info. ANSI colors are assigned to variables at the top of the bash script.

.bash_profile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# High Intensty Colors
GREENH='\[\033[0;92m\]' # Green
BLUEH='\[\033[0;94m\]' # Blue
NC='\[\033[0m\]' # No color
#Git branch in prompt.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
#custom bash prompt with colors
export PS1="\n${BLUEH}\w${GREENH}\$(parse_git_branch)${NC} "
#CLICOLOR will turn colors on or off.
export CLICOLOR=1
#LS_COLORS is not required, and will let you customize the colors
export LSCOLORS=ExFxBxDxCxegedabagacad

Behold The Difference

Before

AFTER!!!!