Skip to content

Instantly share code, notes, and snippets.

@tkalve
Created January 28, 2016 11:51
Show Gist options
  • Save tkalve/2d8b4685aee1334ba55a to your computer and use it in GitHub Desktop.
Save tkalve/2d8b4685aee1334ba55a to your computer and use it in GitHub Desktop.
Colored bash prompt
function color_my_prompt {
local __user_and_host="\[$(tput bold)\]\[\033[38;5;198m\]\u\[$(tput sgr0)\]\[$(tput sgr0)\]\[\033[38;5;255m\] at \[$(tput bold)\]\[$(tput sgr0)\]\[\033[38;5;214m\]\h\[$(tput sgr0)\]"
local __cur_location="\[\033[38;5;255m\]in \[$(tput bold)\]\[$(tput sgr0)\]\[\033[38;5;154m\]\w\[$(tput sgr0)\]\[$(tput sgr0)\]\[\033[38;5;15m\]"
local __git_branch_color="\[$(tput sgr0)\]\[\033[38;5;247m\]"
local __git_branch='`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`'
local __prompt_tail="\n\[$(tput sgr0)\]\[\033[38;5;255m\]\\$\[$(tput sgr0)\]"
local __last_color="\[\033[00m\]"
export PS1="$__user_and_host $__cur_location $__git_branch_color$__git_branch$__prompt_tail$__last_color "
}
color_my_prompt
@tkalve
Copy link
Author

tkalve commented Jan 28, 2016

This will give a colored prompt in the following format:

user at host in ~
$

and show the current git branch like this:

user at host in ~/repo (branch)
$

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