From e16b0b1397df001307ab556ba713ff665359bdd1 Mon Sep 17 00:00:00 2001 From: Artem Sapegin Date: Thu, 14 Mar 2013 23:21:32 +0400 Subject: [PATCH] Bash: Virtualenv stuff. --- includes/bash_aliases.bash | 4 ++++ includes/bash_prompt.bash | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/includes/bash_aliases.bash b/includes/bash_aliases.bash index 8ab290b..a22494c 100644 --- a/includes/bash_aliases.bash +++ b/includes/bash_aliases.bash @@ -99,6 +99,10 @@ alias gw="grunt watch --debug" alias gs="grunt connect watch --debug" gi() { grunt-init $@; } +# Virtualenv +alias venv='test -d ENV && source ./ENV/bin/activate || echo "No Virtualenv in the current folder."' +alias venv-init='test -d ENV && echo "Virtualenv already exists." || virtualenv --no-site-packages ENV; venv' + # Magic Project Opener function proj { cd "$("$HOME/dotfiles/bin/opener.py" "$HOME/Dropbox/Projects" $1 -w project $2)"; } function repo { cd "$("$HOME/dotfiles/bin/opener.py" "$HOME/Dropbox/Projects" $1 -w repo $2)"; } diff --git a/includes/bash_prompt.bash b/includes/bash_prompt.bash index da1f4e1..f4a2e04 100644 --- a/includes/bash_prompt.bash +++ b/includes/bash_prompt.bash @@ -20,6 +20,7 @@ esac prompt_symbol="❯" prompt_clean_symbol="☀ " prompt_dirty_symbol="☂ " +prompt_venv_symbol="☁ " function prompt_command() { # Local or SSH session? @@ -48,6 +49,12 @@ function prompt_command() { fi fi + # Virtualenv + local venv_prompt= + if [ -n "$VIRTUAL_ENV" ]; then + venv_prompt=" $BLUE$prompt_venv_symbol$(basename $VIRTUAL_ENV)$NOCOLOR" + fi + # Only show username if not default local user_prompt= [ "$USER" != "$local_username" ] && user_prompt="$user_color$USER$NOCOLOR" @@ -61,7 +68,7 @@ function prompt_command() { [ -n "$user_prompt" ] || [ -n "$host_prompt" ] && login_delimiter=":" # Format prompt - first_line="$user_prompt$host_prompt$login_delimiter$WHITE\w$NOCOLOR$git_prompt" + first_line="$user_prompt$host_prompt$login_delimiter$WHITE\w$NOCOLOR$git_prompt$venv_prompt" # Text (commands) inside \[...\] does not impact line length calculation which fixes stange bug when looking through the history # $? is a status of last command, should be processed every time prompt prints second_line="\`if [ \$? = 0 ]; then echo \[\$CYAN\]; else echo \[\$RED\]; fi\`\$prompt_symbol\[\$NOCOLOR\] "