Customizing your bash shell for better reading experience in terminal
- December 8, 2020
- Tags: Bash, Command Line, Shell, Terminal
Customizing:
If you are using a lot of terminal / command line and bash shell, you might have experiences that some times it is bit difficult to read the terminal. For example in cases that you have long lists of texts and you print those lists several times, you might lose track, when one list ends and when another list starts as the text is all the same color. As a solution we will add some color coding to the bash shell / terminal. Some bash shells / terminals will have this color coding enabled by default for example in some Linux distros. But for example in my bash shell under Mac OS we don’t have any color coding:
So let’s change that boring look to this one:
To get this style of color coding, we create a .bash_profile file in our home directory for example with Emacs text editor. In the file we will add the following lines:
# You can comment in the file after hashtag and one empty space
# Enable color coding
export CLICOLOR=1
# With the next line we can customize which colors to use and how to for example show username, computer/host name
# and current folder. You can reorder the username, host name and current folder in any order you want. Or you can even
# leave some out, if you don’t need. But in my example I will order them as follow: username @ host name : folder$
# \[\e[32m\] = Use green color
# \u = Username
# \h = Host name
# \W = Current folder
# \[\e[0m\] = Reset text color (so go back to using white color)
export PS1=”\[\e[32m\]\u@\h:\W$ \[\e[0m\]”
And if you aren’t happy with the green color, you can replace it with some other color:
\[\e[30m\] = Black
\[\e[31m\] = Red
\[\e[32m\] = Green
\[\e[33m\] = Yellow
\[\e[34m\] = Blue
\[\e[35m\] = Purple
\[\e[36m\] = Cyan
\[\e[37m\] = White
More Customizing:
If you want to customize even more, you can change the color of the folder, symbolic link, etc. So for example when you run the ls command to list what’s under the current directory, for example the folders would be in red colored text. If you want to do that you can add this following in the .bash_profile after the “export CLICOLOR=1”:
export LSCOLORS=ExFxBxDxCxegedabagacad
These values are read as a pair (for example “Ex”, “Fx”, “Bx”, etc). For example the first value in “Ex” (the value “E”) means that item’s text color should be bold blue. The second value “x” means default background color (so don’t change the background color). Here’s the order what each pair means, first will be the color of folder, second pair will be the color of symbolic link etc:
1 = folder
2 = symbolic link
3 = socket
4 = pipe
5 = executable
6 = block special
7 = character special
8 = executable with setuid bit set
9 = executable with setgid bit set
10 = directory writable to others, with sticky bit
11 = directory writable to others, without sticky bit
And here’s the color values:
a = black
b = red
c = green
d = brown
e = blue
f = magenta
g = cyan
h = light grey
A = bold black (might show as dark grey also)
B = bold red
C = bold green
D = bold brown (might show as yellow also)
E = bold blue
F = bold magenta
G = bold cyan
H = bold light grey
x = default text color / background
Sources:
Articles that I have found useful myself when I was searching information how to customize bash shell. Thanks for these authors for writing these articles. I have quoted the color value and pair value lists from them.
https://osxdaily.com/2012/02/21/add-color-to-the-terminal-in-mac-os-x/
https://www.maketecheasier.com/customize-mac-terminal/