Skip to content

Instantly share code, notes, and snippets.

@felipepodesta
Forked from kimberlysuazo/terminal_settings.md
Created January 6, 2022 12:36
Show Gist options
  • Save felipepodesta/19ac1b8756191cdac59a0118a3523cab to your computer and use it in GitHub Desktop.
Save felipepodesta/19ac1b8756191cdac59a0118a3523cab to your computer and use it in GitHub Desktop.
Setting up your terminal to customize your shell prompt, autocompletion and colors

Setting up a colorful, user-friendly terminal

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.

.gitconfig

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.

.bash_profile

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 direc­tory name

You can find a further list of bash prompt escape sequences here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment