Skip to content

Instantly share code, notes, and snippets.

@rydurham
Created October 25, 2013 05:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rydurham/7149861 to your computer and use it in GitHub Desktop.
Save rydurham/7149861 to your computer and use it in GitHub Desktop.
.bash_aliases 10/24/13
# Some useful Aliases
alias cls=clear
alias composer='/usr/local/bin/composer.phar'
# Add Git Branch Info
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
# Set Color Variables
FGRN="\[\033[32m\]" # foreground green
FYEL="\[\033[33m\]" # foreground yellow
FBLE="\[\033[34m\]" # foreground blue
FMAG="\[\033[35m\]" # foreground magenta
FCYN="\[\033[36m\]" # foreground cyan
FWHT="\[\033[37m\]" # foreground white
FRED="\[\033[31m\]" # foreground red
FGRY="\[\033[38;5;244m\]" # foreground grey
# The following git functions came from https://gist.github.com/woods/31967
# Detect whether the current directory is a git repository.
function is_git_repository {
git branch > /dev/null 2>&1
}
# Determine the branch/state information for this git repository.
function set_git_branch {
# Capture the output of the "git status" command.
git_status="$(git status 2> /dev/null)"
# Set color based on clean/staged/dirty.
if [[ ${git_status} =~ "working directory clean" ]]; then
color="${FGRN}"
elif [[ ${git_status} =~ "Changes to be committed" ]]; then
color="${FYEL}"
else
color="${FRED}"
fi
# Set arrow icon based on status against remote.
remote_pattern="# Your branch is (.*) of"
if [[ ${git_status} =~ ${remote_pattern} ]]; then
if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then
remote="↑"
else
remote="↓"
fi
else
remote=""
fi
diverge_pattern="# Your branch and (.*) have diverged"
if [[ ${git_status} =~ ${diverge_pattern} ]]; then
remote="↕"
fi
# Get the name of the branch.
branch_pattern="^# On branch ([^${IFS}]*)"
if [[ ${git_status} =~ ${branch_pattern} ]]; then
branch=${BASH_REMATCH[1]}
fi
# Set the final branch string.
BRANCH=" ${color}${state}(${branch})${remote}"
}
# Set the full bash prompt.
function set_bash_prompt () {
# Set the PROMPT_SYMBOL variable. We do this first so we don't lose the
# return value of the last command.
#set_prompt_symbol $?
# Set the BRANCH variable.
if is_git_repository ; then
set_git_branch
else
BRANCH=''
fi
# Set the bash prompt variable.
PS1="${debian_chroot:+($debian_chroot)}$FCYN\h $FGRY\w${BRANCH} $FWHT\$ "
}
# Tell bash to execute this function just before displaying its prompt.
PROMPT_COMMAND=set_bash_prompt
#PS1="${debian_chroot:+($debian_chroot)}$FCYN\h$FBLE>$FWHT\w \$(parse_git_branch)$FWHT\$ "
#PS1='\n[\[\e[36;36m\]\u\[\e[0m\]] \[\e[32;2m\]\W \[\e[0m\]\$ '
# [\e[36;36m\]
# PS1='[\u@\h \W]\$ '
# PS1='\[\e[0;34m\][\W]\[\e[m\] '
# ${debian_chroot:+($debian_chroot)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment