Skip to content

Instantly share code, notes, and snippets.

@maumercado
Last active October 10, 2015 03:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maumercado/3628788 to your computer and use it in GitHub Desktop.
Save maumercado/3628788 to your computer and use it in GitHub Desktop.
bash git prompt and others
#!/bin/bash
/usr/local/bin/archey -c
export GOPATH=$HOME/code/go
export GOBIN=$HOME/code/go/bin
export RDOCOPT="--encoding=UTF-8"
export PIP_RESPECT_VIRTUALENV=true
export WORKON_HOME=$HOME/.venv
export EDITOR='subl --wait'
export LC_CTYPE="utf-8"
export PATH="$PATH:./node_modules/.bin:/usr/local/sbin:$GOPATH/bin"
export NODE_ENV="development"
source /usr/local/bin/virtualenvwrapper.sh
source ~/.git-completion.bash
##### CMD Aliases #####
alias ls="ls -G"
alias bi="bundle install --binstubs=./bundler_stubs"
##### SSH Aliases #####
[[ -s /Users/maumercado/.nvm/nvm.sh ]] && . /Users/maumercado/.nvm/nvm.sh # This loads NVM
[[ -r $NVM_DIR/bash_completion ]] && . $NVM_DIR/bash_completion # This loads bash_completion
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
L_YELLOW="\[\033[1;33m\]"
GREEN="\[\033[0;32m\]"
BLUE="\[\033[1;34m\]"
NO_COLOUR="\[\033[0m\]"
CYAN="\[\033[0;36m\]"
PURPLE="\[\033[0;35m\]"
# Determine active Python virtualenv details.
function set_virtualenv () {
if test -z "$VIRTUAL_ENV" ; then
PYTHON_VIRTUALENV=""
else
PYTHON_VIRTUALENV="(`basename \"$VIRTUAL_ENV\"`)"
fi
}
function set_rvm_prompt () {
local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}')
[ "$gemset" != "" ] && echo "(@$gemset)"
}
function parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
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
B_STATE="${GREEN}"
elif [[ ${git_status} =~ .*"Changes to be committed".* ]]; then
B_STATE="${YELLOW}"
else
B_STATE="${RED}"
fi
}
prompt_cmd () {
set_virtualenv
set_git_branch
PS1="┌─\u@\h $L_YELLOW[\w]:$CYAN\${PYTHON_VIRTUALENV}$CYAN\$(set_rvm_prompt)${B_STATE}\$(parse_git_branch)$NO_COLOUR\n└─> "
# PS1="┌─\u@\h $L_YELLOW[\w]:$CYAN\$(set_rvm_prompt)${B_STATE}\$(parse_git_branch)$NO_COLOUR\n└─> "
}
PROMPT_COMMAND=prompt_cmd
# {{{
# Node Completion - Auto-generated, do not touch.
shopt -s progcomp
for f in $(command ls ~/.node-completion); do
f="$HOME/.node-completion/$f"
test -f "$f" && . "$f"
done
# }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment