From 43e67c6e22b414582a4a07261536c13e8f42f96d Mon Sep 17 00:00:00 2001 From: Hexcles Ma Date: Fri, 8 Aug 2014 21:20:41 +0800 Subject: [PATCH 1/2] Add Python virtualenv support --- bash-powerline.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/bash-powerline.sh b/bash-powerline.sh index eec3c91..e74bd7e 100644 --- a/bash-powerline.sh +++ b/bash-powerline.sh @@ -89,6 +89,21 @@ __powerline() { printf " $GIT_BRANCH_SYMBOL$branch$marks " } + __virtualenv() { + # Copied from Python virtualenv's activate.sh script. + # https://github.com/pypa/virtualenv/blob/a9b4e673559a5beb24bac1a8fb81446dd84ec6ed/virtualenv_embedded/activate.sh#L62 + # License: MIT + if [ "x$VIRTUAL_ENV" != "x" ]; then + if [ "`basename \"$VIRTUAL_ENV\"`" == "__" ]; then + # special case for Aspen magic directories + # see http://www.zetadev.com/software/aspen/ + printf "[`basename \`dirname \"$VIRTUAL_ENV\"\``]" + else + printf "(`basename \"$VIRTUAL_ENV\"`)" + fi + fi + } + ps1() { # Check the exit code of the previous command and display different # colors in the prompt accordingly. @@ -98,7 +113,9 @@ __powerline() { local BG_EXIT="$BG_RED" fi - PS1="$BG_BASE1$FG_BASE3 \w $RESET" + PS1="" + PS1+="$BG_BASE0$FG_BASE3$(__virtualenv)$RESET" + PS1+="$BG_BASE1$FG_BASE3 \w $RESET" PS1+="$BG_BLUE$FG_BASE3$(__git_info)$RESET" PS1+="$BG_EXIT$FG_BASE3 $PS_SYMBOL $RESET " } From 4b39dcceca4910e92504ca3e25dd9c18e1ee5f91 Mon Sep 17 00:00:00 2001 From: Hexcles Ma Date: Mon, 26 Oct 2015 14:56:13 -0700 Subject: [PATCH 2/2] Update README about virtualenv support --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index fb7c165..b2c9f11 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Powerline for Bash in pure Bash script. * Git branch: display "+" symbol when current branch is changed but uncommited * Git branch: display "⇡" symbol and the difference in the number of commits when the current branch is ahead of remote (see screenshot) * Git branch: display "⇣" symbol and the difference in the number of commits when the current branch is behind of remote (see screenshot) +* Python virtualenv: display current virtual environment * Platform-dependent prompt symbol for OS X and Linux (see screenshots) * Color code for the previously failed command * Fast execution (no noticable delay)