Skip to content

Instantly share code, notes, and snippets.

@fn-alves
Last active October 30, 2017 01:00
Show Gist options
  • Save fn-alves/15d614a876e53c3b17134d91186d4116 to your computer and use it in GitHub Desktop.
Save fn-alves/15d614a876e53c3b17134d91186d4116 to your computer and use it in GitHub Desktop.
###############################################################################
# Source .profile #
###############################################################################
source ~/.profile
source ~/.colors
###############################################################################
# Third party packages settings and configuration #
###############################################################################
# pyenv
eval "$(pyenv init - bash)"
pyenv global 3.6.3
pyenv virtualenvwrapper
###############################################################################
# Customize the terminal prompt line #
###############################################################################
# colors
export CLICOLOR=1
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
export TERM='xterm-256color'
# disable default venv prompt
export VIRTUAL_ENV_DISABLE_PROMPT=1
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ] ; then
debian_chroot=$(cat /etc/debian_chroot)
fi
###############################################################################
# COLOR PROMPT #
###############################################################################
# set force_color_prompt=no to disable color prompt
force_color_prompt=yes
if [ -n "$force_color_prompt" ] ; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null ; then
color_prompt=yes
else
color_prompt=
fi
fi
function git_prompt {
# if user is in a repository
git_status=$(git status 2> /dev/null)
if [ "$git_status" = "" ]; then
echo ''
else
# get branch name
branch_name=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
commit_status=$(git status 2>/dev/null | tail -n 1)
if [ "$commit_status" = "nothing to commit, working directory clean" ] || [ "$commit_status" = "nada a submeter, diretório de trabalho vazio" ]; then
commit_status_summary="${COLOR_GREEN}clean${COLOR_NC}"
else
commit_status_summary="${COLOR_YELLOW}pending${COLOR_NC}"
fi
echo "${COLOR_CYAN}$branch_name${COLOR_NC}:$commit_status_summary"
fi
}
function venv_prompt {
venv_strip=${VIRTUAL_ENV##*/}
if [ "$venv_strip" = "" ]; then
echo ''
fi
echo ${VIRTUAL_ENV##*/} # this strips the path
}
function get_prompt {
# get venv and git status
venv=$(venv_prompt)
git=$(git_prompt)
# put them together
if [ "$venv" = "" ] && [ "$git" = "" ]; then
prompt=""
elif [ "$venv" = "" ]; then
prompt=$git
elif [ "$git" = "" ]; then
prompt=$venv
else
prompt="$venv:$git"
fi
# format the output
if [ "$prompt" = "" ]; then
echo ""
else
prompt=${prompt//')'/']'}
prompt=${prompt//'('/'['}
echo " ($prompt)"
fi
}
# run these functions before printing each prompt
GET_DATE=`date "+ %d %b %H:%M "`
function prompt_command {
if [ "$color_prompt" = yes ] ; then
export PS1="${debian_chroot:+($debian_chroot)}${MY_COLOR_ORANGE}${GET_DATE}${COLOR_LIGHT_GREEN}\u ${MY_COLOR_GRAY}\h ${MY_COLOR_LIGHT_BLUE}\w${COLOR_NC}$(get_prompt) \n${COLOR_LIGHT_CYAN}\$${COLOR_NC} "
else
export PS1="${debian_chroot:+($debian_chroot)}\u@\h \w $(get_prompt) \$ "
fi
# unset color_prompt force_color_prompt
}
export PROMPT_COMMAND=prompt_command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment