I found that setting up my terminal shell to make it easily readable took alot of digging around. I'm just sharing my settings here to hopefully minimize the setup time for someone else.
Customize colors and add shortcuts for common git commands.
- Open your .gitconfig file
open ~/.gitconfig
- Copy and paste the below:
[color]
branch = auto
diff = auto
status = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold
[color "status"]
added = yellow
changed = green
untracked = cyan
[alias]
co = checkout
ci = commit
st = status
br = branch
This will customize color settings as well as add aliases. For instance, instead of having to type git checkout
, you can type git co
.
- After saving your new .gitconfig settings, run
source ~/.gitconfig
in your terminal to pick up those changes.
For git autocompletion, execute the following in your terminal:
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
- Open your bash_profile
open ~/.bash_profile
- To add the git-completion settings, add this line to your .bash_profile:
test -f ~/.git-completion.bash && . $_
- To autocomplete branch and file names without case sensitivity add:
bind "set completion-ignore-case on"
bind "set show-all-if-ambiguous on"
- To customize your shell prompt with colors and git branch add:
# Shows when there are pending changes
parse_git_dirty() {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working tree clean" ]] && echo "*"
}
# Shows git branch
parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
# This sets the format of the shell prompt
export PS1='\[$(tput setaf 7)\]\u:\[\e[0;34m\]\W\[\e[0;31m\]$(parse_git_branch)\[\e[0m\]\[\e[0;32m\] $ \[\e[0m\]'
# Tuning the colors of the prompt:
export CLICOLOR='true'
export LSCOLORS="gxfxcxdxbxCgCdabagacad"
export EDITOR=vi
- After saving your new .bash_profile settings, run
source ~/.bash_profile
in your terminal to pick up those changes.
I have customized my shell prompt in this format: username:current-directory[git-branch] $
To break it down a little bit, \[\e[0;34m\]\W
sets the current working directory color to blue. \[$(tput setaf 7)\]\u:
sets the username followed by :
to white
Some color codes
Black 0;30
Blue 0;34
Green 0;32
Cyan 0;36
Red 0;31
Purple 0;35
Brown 0;33
Some useful bash prompt escape sequences:
\h the hostname up to the first `.'
\u the username of the current user
\w working directory path
\W current working directory name
You can find a further list of bash prompt escape sequences here.