Skip to content

Instantly share code, notes, and snippets.

@samitnuk
Last active February 3, 2019 18:09
Show Gist options
  • Save samitnuk/dcf0a14f0160ab5e93909cc32cd12f25 to your computer and use it in GitHub Desktop.
Save samitnuk/dcf0a14f0160ab5e93909cc32cd12f25 to your computer and use it in GitHub Desktop.
# My changes [ begin ] ---------------------------------------------------------------------------
# The various escape codes that we can use to color our prompt.
RED="\[\033[0;31m\]"
YELLOW="\[\033[1;33m\]"
GREEN="\[\033[1;32m\]"
BLUE="\[\033[1;34m\]"
PURPLE="\[\033[0;35m\]"
LIGHT_RED="\[\033[1;31m\]"
LIGHT_GREEN="\[\033[1;32m\]"
WHITE="\[\033[1;37m\]"
LIGHT_GRAY="\[\033[0;37m\]"
COLOR_NONE="\[\e[0m\]"
# Determine active Python virtualenv details.
function set_virtualenv () {
if test -z "$VIRTUAL_ENV"
then
PYTHON_VIRTUALENV=""
else
PYTHON_VIRTUALENV="venv:${GREEN}`basename \"$VIRTUAL_ENV\"`${COLOR_NONE} "
fi
}
function parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
function set_git_branch() {
# Get the name of the branch.
branch=$(parse_git_branch)
if [ "$branch" == "" ]
then
BRANCH=""
else
# Set the final branch string.
BRANCH="git:${YELLOW}${branch}${COLOR_NONE} "
fi
}
function set_bash_prompt () {
set_git_branch
set_virtualenv
if [ "$BRANCH" == "" ] && [ "$PYTHON_VIRTUALENV" == "" ]; then
magic_number=9
else
if [ ! "$BRANCH" == "" ] && [ ! "$PYTHON_VIRTUALENV" == "" ]
then
magic_number=55
else
magic_number=32
fi
fi
PS1="$(printf "%*s" $(($(tput cols)-${#PWD}-${#BRANCH}-${#PYTHON_VIRTUALENV}+${magic_number})) "" | sed "s/ / /g") ${BRANCH}${PYTHON_VIRTUALENV}[${BLUE}\w${COLOR_NONE}]\n"
PS1+=" ${GREEN}>${COLOR_NONE} "
}
# --- For Elementary OS
precmd() { set_bash_prompt; }
# --- For Mac OS
# PROMPT_COMMAND=set_bash_prompt
export VIRTUAL_ENV_DISABLE_PROMPT=1
# This path can be found with `which python3`
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=~/Projects/.virtualenvs
. /usr/local/bin/virtualenvwrapper.sh
# Check for separate file with aliases
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# My changes [ end ] -----------------------------------------------------------------------------
# My changes in ~/.bash_profile for MAC OS [ begin ] ---------------------------------------------
source ~/.bashrc
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
# Tell ls to be colourful
export CLICOLOR=1
export LSCOLORS=Exfxcxdxbxegedabagacad
# Tell grep to highlight matches
export GREP_OPTIONS='--color=auto'
# Tell terminal to store only unique commands
export HISTCONTROL=ignoredups
# brew install git bash-completion
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
# brew install pyenv
export PATH="/Users/samitnuk/.pyenv:$PATH"
eval "$(pyenv init -)"
# My changes in ~/.bash_profile for MAC OS [ end ] -----------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment