Bash profile setup
#enables git prompt in terminal
source ~/.git-prompt.sh
#enables color in the terminal bash shell export
CLICOLOR=1
#sets up the color scheme for list export
LSCOLORS=gxfxcxdxbxegedabagacad
#enables color for iTerm
export TERM=xterm-256color
#sets up proper alias commands when called
alias ls='ls -G'
alias ll='ls -hl'
alias lso="ls -alG | awk '{k=0;for(i=0;i<=8;i++)k+=((substr(\$1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf(\" %0o \",k);print}'"
#docker alias for pretty formated output
alias dps='docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}"'
#history command customizations
export HISTCONTROL=erasedups
export HISTSIZE=25000
shopt -s histappend
export HISTIGNORE="pwd:ls:ls -ltr:ls -al:clear"
#go to the root of a Drupal site
function dr(){
origDir=$(pwd)
while [[ ! -e xmlrpc.php && ! -e cron.php ]]; do
if [[ $(pwd) == "/" ]] ; then
echo "Drupal root not found."
cd $origDir
break
fi
cd ..
done
echo "Moved to $(pwd)"
}
#bash command line w/ vi bindings
set -o vi
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
export PATH="$HOME/.composer/vendor/bin:$PATH"
export PATH="$PATH:./node_modules/.bin"
# Check that terminfo exists before changing TERM var to xterm-256color
# Prevents prompt flashing in Mac OS X 10.6 Terminal.app
if [ -e /usr/share/terminfo/x/xterm-256color ]; then
export TERM='xterm-256color'
fi
tput sgr 0 0
# Base styles and color palette
BOLD=$(tput bold)
RESET=$(tput sgr0)
SOLAR_YELLOW=$(tput setaf 259)
SOLAR_ORANGE=$(tput setaf 166)
SOLAR_RED=$(tput setaf 124)
SOLAR_MAGENTA=$(tput setaf 125)
SOLAR_VIOLET=$(tput setaf 61)
SOLAR_BLUE=$(tput setaf 39)
SOLAR_CYAN=$(tput setaf 199)
SOLAR_GREEN=$(tput setaf 64)
SOLAR_WHITE=$(tput setaf 254)
style_user="\[${RESET}${SOLAR_CYAN}\]"
style_host="\[${RESET}${SOLAR_CYAN}\]"
style_path="\[${RESET}${SOLAR_CYAN}\]"
style_chars="\[${RESET}${SOLAR_WHITE}\]"
style_branch="${SOLAR_YELLOW}"
if [[ "$SSH_TTY" ]]; then
# connected via ssh
style_host="\[${BOLD}${SOLAR_RED}\]"
elif [[ "$USER" == "root" ]]; then
# logged in as root
style_user="\[${BOLD}${SOLAR_RED}\]"
fi
is_git_repo() {
$(git rev-parse --is-inside-work-tree &> /dev/null)
}
is_git_dir() {
$(git rev-parse --is-inside-git-dir 2> /dev/null)
}
get_git_branch() {
local branch_name
# Get the short symbolic ref
branch_name=$(git symbolic-ref --quiet --short HEAD 2> /dev/null) ||
# If HEAD isn't a symbolic ref, get the short SHA
branch_name=$(git rev-parse --short HEAD 2> /dev/null) ||
# Otherwise, just give up
branch_name="(unknown)"
printf $branch_name
}
# Git status information
prompt_git() {
local git_info git_state uc us ut st
if ! is_git_repo || is_git_dir; then
return 1
fi
git_info=$(get_git_branch)
# Check for uncommitted changes in the index
if ! $(git diff --quiet --ignore-submodules --cached); then
uc="+"
fi
# Check for unstaged changes
if ! $(git diff-files --quiet --ignore-submodules --); then
us="!"
fi
# Check for untracked files
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
ut="?"
fi
# Check for stashed files
if $(git rev-parse --verify refs/stash &>/dev/null); then
st="$"
fi
git_state=$uc$us$ut$st
# Combine the branch name and state information
if [[ $git_state ]]; then
git_info="$git_info[$git_state]"
fi
printf "${SOLAR_WHITE} - ${style_branch}${git_info}"
}
# If not running interactively, exit
[ -z "$PS1" ] && return
# Set the terminal title to the current working directory
PS1="\n\[\033]0;\w\007\]"
# Build the prompt
PS1+="${style_user}\u" # Username
PS1+="${style_user}@" # @
PS1+="${style_user}\h" # Host
PS1+="${style_host}:" # :
PS1+="${style_path}\w" # Working directory
PS1+="${style_branch}\$(__git_ps1)" # Working directory
PS1+="\$(prompt_git)" # Git details
PS1+="\n" # Newline
PS1+="${style_chars}\$ \[${RESET}\]" # $ (and reset color)
function ssh () {
servername=$(echo $@ | sed -E 's|([- a-zA-Z0-9:/]+)( *[^@ ]*@)([^@ ]*)|\3|')
echo -ne "\033]0;${servername}\007";
/usr/bin/ssh $@
}
test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash"