From 700b2ae006488c17160f2f7bb841fd2d9bacc089 Mon Sep 17 00:00:00 2001 From: Chris Coley <chris@codingallnight.com> Date: Sun, 6 Sep 2015 22:20:40 -0700 Subject: [PATCH] Refactoring bashrc and moving Git auto completion and Git prompt to where they belong. Also adding my current as an example. --- bashrc | 17 ++--------------- bashrc.local.example | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 bashrc.local.example diff --git a/bashrc b/bashrc index b912b30..7ff30d9 100644 --- a/bashrc +++ b/bashrc @@ -49,21 +49,12 @@ if [ -n "$force_color_prompt" ]; then fi fi -# Enable Git prompt -GIT_PS1_SHOWDIRTYSTATE=yes -GIT_PS1_SHOWCOLORHINTS=yes -GIT_PS1_HIDE_IF_PWD_IGNORED=yes -if [ -f ~/.git-prompt.sh ]; then - source ~/.git-prompt.sh -fi - if [ "$color_prompt" = yes ] && [ "`id -u`" -eq 0 ]; then # Red prompt for root - PS1='${debian_chroot:+($debian_chroot)}\[\033[31m\][\w]\[\033[00m\] \$ ' + PS1='${debian_chroot:+($debian_chroot)}\h:\[\033[31m\][\w]\[\033[00m\] \$ ' else # Default prompt for everyone else - #PS1='${debian_chroot:+($debian_chroot)}\h:\[\033[38;5;25m\][\w]\[\033[00m\] \$ ' - PROMPT_COMMAND='__git_ps1 "${debian_chroot:+($debian_chroot)}\h:\[\033[38;5;25m\][\w]\[\033[00m\]" " \$ " " {%s}"' + PS1='${debian_chroot:+($debian_chroot)}\h:\[\033[38;5;25m\][\w]\[\033[00m\] \$ ' fi unset color_prompt force_color_prompt @@ -108,7 +99,3 @@ if [ -f ~/.bashrc.local ]; then . ~/.bashrc.local fi -# Enable Git auto completion -if [ -f ~/.git-completion.bash ]; then - . ~/.git-completion.bash -fi diff --git a/bashrc.local.example b/bashrc.local.example new file mode 100644 index 0000000..dd56eb2 --- /dev/null +++ b/bashrc.local.example @@ -0,0 +1,43 @@ + +# VirtualEnv Wrapper +export WORKON_HOME=~/.virtualenvs +source /usr/local/bin/virtualenvwrapper.sh + +# AutoENV +AUTOENV_ENV_FILENAME=.autoenv +source ~/.autoenv/activate.sh + +# Enable Git auto completion +if [ -f ~/.git-completion.bash ]; then + . ~/.git-completion.bash +fi + +# Enable Git prompt +if [ -f ~/.git-prompt.sh ]; then + GIT_PS1_SHOWDIRTYSTATE=yes + GIT_PS1_SHOWCOLORHINTS=yes + GIT_PS1_HIDE_IF_PWD_IGNORED=yes + source ~/.git-prompt.sh +fi + +# Override prompt to include virtualenv name and git branch name +add_venv_info () { + if [ -z "$VIRTUAL_ENV_DISABLE_PROMPT" ] ; then + VIRT_ENV_TXT="" + if [ "x" != x ] ; then + VIRT_ENV_TXT="" + else + if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then + # special case for Aspen magic directories + # see http://www.zetadev.com/software/aspen/ + VIRT_ENV_TXT="[`basename \`dirname \"$VIRTUAL_ENV\"\``]" + elif [ "$VIRTUAL_ENV" != "" ]; then + VIRT_ENV_TXT="(`basename \"$VIRTUAL_ENV\"`)" + fi + fi + if [ "${VIRT_ENV_TXT}" != "" ]; then + echo ${VIRT_ENV_TXT}" " + fi + fi +} +PROMPT_COMMAND='__git_ps1 "${debian_chroot:+($debian_chroot)}$(add_venv_info)\h:\[\033[38;5;25m\][\w]\[\033[00m\]" " \$ " " {%s}"' -- GitLab