Skip to content

Instantly share code, notes, and snippets.

@skozz
Forked from NoobsArePeople2/gist:4490307
Last active December 31, 2015 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skozz/8036769 to your computer and use it in GitHub Desktop.
Save skozz/8036769 to your computer and use it in GitHub Desktop.
Color your bash.
1. Open Terminal move to your home folder:
`cd ~`
2. Enable git colors:
`git config --global color.ui true`
3. Make a file called ".colors":
`touch .colors`
4. Open .colors and paste the following:
```bash
## Colors
# Reset
off='\033[0m' # Text Reset
# Regular Colors
black='\033[0;30m' # Black
red='\033[0;31m' # Red
green='\033[0;32m' # Green
yellow='\033[0;33m' # Yellow
blue='\033[0;34m' # Blue
purple='\033[0;35m' # Purple
cyan='\033[0;36m' # Cyan
white='\033[0;37m' # White
# Bold
Black='\033[1;30m' # Black
Red='\033[1;31m' # Red
Green='\033[1;32m' # Green
Yellow='\033[1;33m' # Yellow
Blue='\033[1;34m' # Blue
Purple='\033[1;35m' # Purple
Cyan='\033[1;36m' # Cyan
White='\033[1;37m' # White
# Underline
_black_='\033[4;30m' # Black
_red_='\033[4;31m' # Red
_green_='\033[4;32m' # Green
_yellow_='\033[4;33m' # Yellow
_blue_='\033[4;34m' # Blue
_purple_='\033[4;35m' # Purple
_cyan_='\033[4;36m' # Cyan
_white_='\033[4;37m' # White
# Background
on_black='\033[0;40m' # Black
on_red='\033[0;41m' # Red
on_green='\033[0;42m' # Green
on_yellow='\033[0;43m' # Yellow
on_blue='\033[0;44m' # Blue
on_purple='\033[0;45m' # Purple
on_cyan='\033[0;46m' # Cyan
on_white='\033[0;47m' # White
# High Intensty
bLACK='\033[0;90m' # Black
rED='\033[0;91m' # Red
gREEN='\033[0;92m' # Green
yELLOW='\033[0;93m' # Yellow
bLUE='\033[0;94m' # Blue
pURPLE='\033[0;95m' # Purple
cYAN='\033[0;96m' # Cyan
wHITE='\033[0;97m' # White
# Bold High Intensty
BLACK='\033[1;90m' # Black
RED='\033[1;91m' # Red
GREEN='\033[1;92m' # Green
YELLOW='\033[1;93m' # Yellow
BLUE='\033[1;94m' # Blue
PURPLE='\033[1;95m' # Purple
CYAN='\033[1;96m' # Cyan
WHITE='\033[1;97m' # White
# High Intensty backgrounds
on_BLACK='\033[0;100m' # Black
on_RED='\033[0;101m' # Red
on_GREEN='\033[0;102m' # Green
on_YELLOW='\033[0;103m' # Yellow
on_BLUE='\033[0;104m' # Blue
on_PURPLE='\033[10;95m' # Purple
on_CYAN='\033[0;106m' # Cyan
on_WHITE='\033[0;107m' # White
```
5. Open .bash_profile and add the following line:
`source ~/.colors`
6. Add the following lines to .bash_profile
```
export GIT_PS1_SHOWDIRTYSTATE=true
export GIT_PS1_SHOWUNTRACKEDFILES=true
export CLICOLOR=1
```
7. Below the lines from step #6 add the following function:
```
function color_my_prompt {
local user_and_host="\[${wHITE}\][\u]"
local current_location="\[${wHITE}\]\W"
local git_branch_color="\[${pURPLE}\]"
local git_branch='`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`'
local prompt_tail="\[${wHITE}\]$"
local last_color="\[${off}\]"
export PS1="$user_and_host $current_location $git_branch_color$git_branch$prompt_tail$last_color "
}
```
8. Below the function from step #7 add:
`color_my_prompt`
8. In Terminal type:
`source .bash_profile`
### References
* [Colors In Git](http://git-scm.com/book/en/Customizing-Git-Git-Configuration#Colors-in-Git)
* [Stackoverflow](http://dev-spout.blogspot.com/2011/07/mac-terminal-colors-git-prompt.html)
* [Terminal Colors in Git Prompt](http://dev-spout.blogspot.com/2011/07/mac-terminal-colors-git-prompt.html)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment