Last active
December 31, 2015 18:48
-
-
Save thecarlhall/5511899 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
################################################################################ | |
# terminal/prompt stuff | |
################################################################################ | |
BLUE="\[\033[0;34m\]" | |
CYAN="\[\033[0;36m\]" | |
GREEN="\[\033[0;32m\]" | |
RED="\[\033[0;31m\]" | |
MAGENTA="\[\033[0;35m\]" | |
YELLOW="\[\033[0;33m\]" | |
WHITE="\[\033[1;37m\]" | |
ENDCOLOR="\[\033[0m\]" | |
# Colored ls output | |
export CLICOLOR=1 | |
export LSCOLORS=dxfxcxdxbxegedabagacad | |
# export TERM="xterm-color" | |
# Turn off the bell | |
# xset b 0 | |
COLOR1=$CYAN | |
COLOR2=$GREEN | |
COLOR3=$CYAN | |
COLOR4=$RED | |
if [ $UID = 0 ]; then | |
# I am root | |
COLOR2=$RED | |
fi | |
parse_git_branch() { | |
git rev-parse --git-dir &> /dev/null | |
git_status="$(git status 2> /dev/null)" | |
branch_pattern="^On branch ([^${IFS}]*)" | |
remote_pattern="^Your branch is ([[:alnum:]]*)" | |
diverge_pattern="^Your branch and (.*) have diverged" | |
if [[ ${git_status} =~ ${branch_pattern} ]]; then | |
branch=${BASH_REMATCH[1]} | |
if [[ ${git_status} =~ "Changes to be committed" ]]; then | |
state="${state}${GREEN}S" | |
fi | |
if [[ ${git_status} =~ "Changes not staged for commit" ]]; then | |
state="${state}${YELLOW}C" | |
fi | |
if [[ ${git_status} =~ "Untracked files" ]]; then | |
state="${state}${CYAN}U" | |
fi | |
# add an else if or two here if you want to get more specific | |
if [[ ${git_status} =~ ${remote_pattern} ]]; then | |
if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then | |
remote="${YELLOW}↑" | |
else | |
remote="${YELLOW}↓" | |
fi | |
fi | |
if [[ ${git_status} =~ ${diverge_pattern} ]]; then | |
remote="${YELLOW}↕" | |
fi | |
if [[ -n ${state} ]]; then | |
state=" ${state}" | |
fi | |
echo -e " $GREEN[${YELLOW}${branch}${remote}${state}${GREEN}]" | |
fi | |
} | |
parse_rvm_gemset() { | |
if [[ -f ./Gemfile ]]; then | |
GEMSET=$(basename "$GEM_HOME") | |
echo -e " $GREEN[${RED}${GEMSET}${GREEN}]" | |
fi | |
} | |
prompt_func() { | |
nametab $(basename $(pwd)) | |
export PS1="$COLOR2($COLOR3\u@$RED\h$COLOR2::$(date '+%Y-%m-%d %H:%M')) $COLOR2($COLOR3\w$COLOR2)$(parse_git_branch)$(parse_rvm_gemset)\n$COLOR1\$$ENDCOLOR " | |
} | |
alias prompt_func=prompt_func | |
export PROMPT_COMMAND="history -a; history -c; history -r; prompt_func" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment