Created
May 30, 2014 08:41
-
-
Save billglover/77291d1ed65e6fe12223 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
export EDITOR=vim | |
GREEN="\[\e[0;32m\]" | |
BLUE="\[\e[0;34m\]" | |
RED="\[\e[0;31m\]" | |
YELLOW="\[\e[0;33m\]" | |
COLOREND="\[\e[00m\]" | |
# Aliases | |
alias c='clear' | |
alias reboot='sudo reboot' | |
alias update='sudo apt-get upgrade' | |
alias ls='ls --color=auto' | |
alias ll='ls -la --color=auto' | |
alias l.='ls -d .* --color=auto' | |
alias grep='grep --color=auto' | |
alias egrep='egrep --color=auto' | |
alias fgrep='fgrep --color=auto' | |
alias vi=vim | |
alias svi='sudo vi' | |
alias vis='vim "+set si"' | |
alias edit='vim' | |
# Responsive Prompt | |
parse_git_branch() { | |
if [[ -f "$BASH_COMPLETION_DIR/git-completion.bash" ]]; then | |
branch=`__git_ps1 "%s"` | |
else | |
ref=$(git-symbolic-ref HEAD 2> /dev/null) || return | |
branch="${ref#refs/heads/}" | |
fi | |
if [[ `tput cols` -lt 110 ]]; then | |
branch=`echo $branch | sed s/feature/f/1` | |
branch=`echo $branch | sed s/hotfix/h/1` | |
branch=`echo $branch | sed s/release/\r/1` | |
branch=`echo $branch | sed s/master/mstr/1` | |
branch=`echo $branch | sed s/develop/dev/1` | |
fi | |
if [[ $branch != "" ]]; then | |
if [[ $(git status 2> /dev/null | tail -n1) == "nothing to commit, working directory clean" ]]; then | |
echo "${GREEN}$branch${COLOREND} " | |
else | |
echo "${RED}$branch${COLROEND} " | |
fi | |
fi | |
} | |
working_directory() { | |
dir=`pwd` | |
in_home=0 | |
if [[ `pwd` =~ ^"$HOME"(/|$) ]]; then | |
dir="~${dir#$HOME}" | |
in_home=1 | |
fi | |
workingdir="" | |
if [[ `tput cols` -lt 110 ]]; then | |
first="/`echo $dir | cut -d / -f 2`" | |
letter=${first:0:2} | |
if [[ $in_home == 1 ]]; then | |
letter="~$letter" | |
fi | |
proj=`echo $dir | cut -d / -f 3` | |
beginning="$letter/$proj" | |
end=`echo "$dir" | rev | cut -d / -f1 | rev` | |
if [[ $proj == "" ]]; then | |
workingdir="$dir" | |
elif [[ $proj == "~" ]]; then | |
workingdir="$dir" | |
elif [[ $dir =~ "$first/$proj"$ ]]; then | |
workingdir="$beginning" | |
elif [[ $dir =~ "$first/$proj/$end"$ ]]; then | |
workingdir="$beginning/$end" | |
else | |
workingdir="$beginning/./$end" | |
fi | |
else | |
workingdir="$dir" | |
fi | |
echo -e "${YELLOW}$workingdir${COLOREND} " | |
} | |
parse_remote_state() { | |
remote_state=$(git status -sb 2> /dev/null | grep -oh "\[.*\]") | |
if [[ "$remote_state" != "" ]]; then | |
out="${BLUE}[${COLOREND}" | |
if [[ "$remote_state" == *ahead* ]] && [[ "$remote_state" == *behind* ]]; then | |
behind_num=$(echo "$remote_state" | grep -oh "behind \d*" | grep -oh "\d*$") | |
ahead_num=$(echo "$remote_state" | grep -oh "ahead \d*" | grep -oh "\d*$") | |
out="$out${RED}$behind_num${COLOREND},${GREEN}$ahead_num${COLOREND}" | |
elif [[ "$remote_state" == *ahead* ]]; then | |
ahead_num=$(echo "$remote_state" | grep -oh "ahead \d*" | grep -oh "\d*$") | |
out="$out${GREEN}$ahead_num${COLOREND}" | |
elif [[ "$remote_state" == *behind* ]]; then | |
behind_num=$(echo "$remote_state" | grep -oh "behind \d*" | grep -oh "\d*$") | |
out="$out${RED}$behind_num${COLOREND}" | |
fi | |
out="$out${BLUE}]${COLOREND}" | |
echo "$out " | |
fi | |
} | |
prompt() { | |
if [[ $? -eq 0 ]]; then | |
exit_status="${BLUE}.${COLOREND} " | |
else | |
exit_status="${RED}.${COLOREND} " | |
fi | |
PS1="$(working_directory)$(parse_git_branch)$(parse_remote_state)$exit_status" | |
} | |
PROMPT_COMMAND=prompt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment