Skip to content

Instantly share code, notes, and snippets.

@gjackson12
Created October 8, 2018 19:58
Show Gist options
  • Select an option

  • Save gjackson12/da70e0955fc75dbd1462ad299086c1c8 to your computer and use it in GitHub Desktop.

Select an option

Save gjackson12/da70e0955fc75dbd1462ad299086c1c8 to your computer and use it in GitHub Desktop.
Sample bash_profile
# export PATH=$PATH:/usr/bin
if [ -f ~/.bash_colors ]; then
source ~/.bash_colors
fi
## RBENV ##
eval "$(rbenv init -)"
## NVM ##
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
export PATH=/usr/local/bin:$PATH
export PYTHONPATH="/usr/local/Cellar/python/3.7.0/bin/python3:$PYTHONPATH"
## PS1 ##
## Shell Prompt ##
__prompt_command() {
EXIT="$?"
PS1=""
if [ $EXIT -eq 0 ]; then
PS1+="${green}[\!] "
else
PS1+="${red}[\!] "
fi
# If logged in via ssh shows the ip of the server
if [ -n "$SSH_CLIENT" ]; then
IFS=" " read -ra SERVER_IP <<< ${SSH_CONNECTION}
PS1+="${yellow}("${SERVER_IP[2]}") "
fi
PS1+="${bold_purple}\W "
# Add rbenv to prompt
PS1+="${green}$(rbenv version | sed -e 's/ .*//') "
# Check if inside git repo
local git_status="$(git status -unormal 2>&1)"
if ! [[ "$git_status" =~ not\ a\ git\ repo ]]; then
# Parse the porcelain output of git status
if [[ "$git_status" =~ nothing\ to\ commit ]]; then
local Color_On=${green}
elif [[ "$git_status" =~ nothing\ added\ to\ commit\ but\ untracked\ files\ present ]]; then
local Color_On=${purple}
else
local Color_On=${red}
fi
if [[ "$git_status" =~ On\ branch\ ([^[:space:]]+) ]]; then
branch=${BASH_REMATCH[1]}
else
# Detached HEAD. (branch=HEAD is a faster alternative.)
branch="$(git describe --all --contains --abbrev=4 HEAD 2> /dev/null || echo HEAD)"
fi
# Add the result to prompt
PS1+="${Color_On}[${branch}] "
fi
PS1+="${normal}\$ "
}
## Execute __prompt_command every time PS1 is printed ##
PROMPT_COMMAND=__prompt_command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment