Skip to content

Instantly share code, notes, and snippets.

@codebudo
Created October 24, 2012 20:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codebudo/3948788 to your computer and use it in GitHub Desktop.
Save codebudo/3948788 to your computer and use it in GitHub Desktop.
Bash profile for fancy prompt
# fancy prompt
COLOR_NONE="\[\e[0m\]"
BLACK_BOLD="\[\e[30;1m\]"
RED_BOLD="\[\e[31;1m\]"
GREEN_BOLD="\[\e[32;1m\]"
BROWN_BOLD="\[\e[33;1m\]"
BLUE_BOLD="\[\e[34;1m\]"
PINK_BOLD="\[\e[35;1m\]"
CYAN_BOLD="\[\e[36;1m\]"
WHITE_BOLD="\[\e[37;1m\]"
LIGHTNING_BOLT="⚡"
UP_ARROW="↑"
DOWN_ARROW="↓"
UD_ARROW="↕"
FF_ARROW="→"
MIDDOT="•"
# CRAZY PROMPT STUFF
function parse_git_branch {
branch_pattern="^# On branch ([^${IFS}]*)"
remote_pattern_ahead="# Your branch is ahead of"
remote_pattern_behind="# Your branch is behind"
remote_pattern_ff="# Your branch (.*) can be fast-forwarded."
diverge_pattern="# Your branch and (.*) have diverged"
git_status="$(git status 2> /dev/null)"
if [[ ! ${git_status} =~ ${branch_pattern} ]]; then
# Rebasing?
toplevel=$(git rev-parse --show-toplevel 2> /dev/null)
[[ -z "$toplevel" ]] && return
[[ -d "$toplevel/.git/rebase-merge" || -d "$toplevel/.git/rebase-apply" ]] && {
sha_file="$toplevel/.git/rebase-merge/stopped-sha"
[[ -e "$sha_file" ]] && {
sha=`cat "${sha_file}"`
}
echo "${PINK_BOLD}(rebase in progress)${COLOR_NONE} ${sha}"
}
return
fi
# don't show master branch
branch="(${BASH_REMATCH[1]})"
if [[ ${branch} =~ "master" ]]; then
branch=""
fi
# Dirty?
if [[ ! ${git_status} =~ "working directory clean" ]]; then
[[ ${git_status} =~ "modified:" ]] && {
git_is_dirty="${RED_BOLD}${LIGHTNING_BOLT}"
}
[[ ${git_status} =~ "Untracked files" ]] && {
git_is_dirty="${git_is_dirty}${WHITE_BOLD}${MIDDOT}"
}
[[ ${git_status} =~ "new file:" ]] && {
git_is_dirty="${git_is_dirty}${GREEN_BOLD}+"
}
[[ ${git_status} =~ "deleted:" ]] && {
git_is_dirty="${git_is_dirty}${RED_BOLD}-"
}
[[ ${git_status} =~ "renamed:" ]] && {
git_is_dirty="${git_is_dirty}${BROWN_BOLD}→"
}
fi
# Are we ahead of, behind, or diverged from the remote?
if [[ ${git_status} =~ ${remote_pattern_ahead} ]]; then
remote="${CYAN_BOLD}${UP_ARROW}"
elif [[ ${git_status} =~ ${remote_pattern_behind} ]]; then
remote="${CYAN_BOLD}${DOWN_ARROW}"
elif [[ ${git_status} =~ ${diverge_pattern} ]]; then
remote="${CYAN_BOLD}${UD_ARROW}"
fi
if [[ ${git_status} =~ ${remote_pattern_ff} ]]; then
remote_ff="${BLACK_BOLD}${FF_ARROW}"
fi
echo "${remote}${remote_ff}${BROWN_BOLD}${branch}${COLOR_NONE}${git_is_dirty}${COLOR_NONE}"
}
function set_prompt {
PS1="\\u"
PS1="${PS1}@"
PS1="${PS1}\\h"
#PS1="${PS1}$(rvm_gemset)"
PS1="${PS1}:"
PS1="${PS1}\\W"
PS1="${PS1}$(parse_git_branch)"
PS1="${PS1} \\$ "
}
PROMPT_COMMAND=set_prompt
@lewinski
Copy link

Looks familiar.

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