Created
September 1, 2011 15:54
-
-
Save lholden/1186487 to your computer and use it in GitHub Desktop.
My Bash Prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare -r MAX_PATH_LENGTH=40 | |
declare -r GIT_PS1_SHOWDIRTYSTATE=true | |
declare -r COLOR_PATH="\[\e[34;1m\]" | |
declare -r COLOR_EXTRAS="\[\e[35m\]" | |
declare -r COLOR_USER="\[\e[1;36;40m\]" | |
declare -r COLOR_ROOT="\[\e[1;31;40m\]" | |
declare -r COLOR_HOST="" | |
declare -r COLOR_RESET="\[\e[0m\]" | |
function shorten_path { | |
declare path="$1" | |
declare prefix | |
[[ "$path" =~ (~) ]] && prefix="~/" | |
if [[ ${#path} -gt $MAX_PATH_LENGTH ]]; then | |
path=${path: -$(($MAX_PATH_LENGTH - ${#prefix}))} | |
[[ "$path" =~ ^[^/]*/(.*) ]] && path="$prefix(...)${BASH_REMATCH[1]}" | |
fi | |
echo $path | |
} | |
function prompt_git { | |
[[ $(type -t __git_ps1) ]] || return | |
declare branch="$(__git_ps1)" | |
if [[ ! -z "$branch" ]]; then | |
echo " [${branch:2:((${#branch} - 3))}]" | |
fi | |
} | |
function prompt_rvm { | |
[[ -f ~/.rvm/bin/rvm-prompt ]] || return | |
echo " [$(~/.rvm/bin/rvm-prompt i v g s)]" | |
} | |
function prompt_jobs { | |
declare num_jobs=$1 | |
declare jobs_str | |
case $num_jobs in | |
(0) return ;; | |
(1) jobs_str="job";; | |
(*) jobs_str="jobs";; | |
esac | |
echo " [$num_jobs $jobs_str]" | |
} | |
declare color_by_id | |
case $EUID in | |
(0) color_by_id=$COLOR_ROOT ;; | |
(*) color_by_id=$COLOR_USER ;; | |
esac | |
export PS1="( $color_by_id\u$COLOR_RESET@$COLOR_HOST\h$COLOR_RESET:$COLOR_PATH\$(shorten_path '\w')$COLOR_RESET$COLOR_EXTRAS\$(prompt_rvm)\$(prompt_git)\$(prompt_jobs \j)$COLOR_RESET )\n\$ " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like this:
( lori@Oblivion:~/Projects/whatever [ree-1.8.7@whatever] [master] )
$
but with colors ;)