From d10f61310043d2b9efe55b5485fc32e5e14405dd Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Thu, 18 Sep 2014 21:24:14 +0200 Subject: [PATCH] Moved VirtualEnv template to git-prompt-colors.sh, fixed replacement --- git-prompt-colors.sh | 11 ++++++++--- gitprompt.sh | 23 ++++++++++++++++------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/git-prompt-colors.sh b/git-prompt-colors.sh index 88680c4..c50d2f3 100644 --- a/git-prompt-colors.sh +++ b/git-prompt-colors.sh @@ -23,13 +23,18 @@ define_git_prompt_colors() { # will be replaced with the exit code of the last command # e.g. # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 - # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 - GIT_PROMPT_COMMAND_FAIL="${Red}✘ " # indicator if the last command returned with an exit code of other than 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" - GIT_PROMPT_START_ROOT="${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " diff --git a/gitprompt.sh b/gitprompt.sh index 6f95df0..759844d 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -159,9 +159,12 @@ function git_prompt_config() else local ps="$LAST_COMMAND_INDICATOR" if [[ -n "$VIRTUAL_ENV" ]]; then - ps="$ps($Blue$(basename \"$VIRTUAL_ENV\")$ResetColor) " - elif [[ -n "$CONDA_DEFAULT_ENV" ]]; then - ps="$ps($Blue$(basename \"$CONDA_DEFAULT_ENV\")$ResetColor) " + VENV=$(basename "${VIRTUAL_ENV}") + ps="${ps}${GIT_PROMPT_VIRTUALENV/_VIRTUALENV_/${VENV}}" + fi + if [[ -n "$CONDA_DEFAULT_ENV" ]]; then + VENV=$(basename "${CONDA_DEFAULT_ENV}") + ps="${ps}${GIT_PROMPT_VIRTUALENV/_VIRTUALENV_/${VENV}}" fi EMPTY_PROMPT="$ps$PROMPT_START$($prompt_callback)$PROMPT_END" fi @@ -251,6 +254,7 @@ function updatePrompt() { local GIT_STASHED=${GitStatus[6]} local GIT_CLEAN=${GitStatus[7]} + local NEW_PROMPT="$EMPTY_PROMPT" if [[ -n "$GitStatus" ]]; then local STATUS="${PROMPT_LEADING_SPACE}${GIT_PROMPT_PREFIX}${GIT_PROMPT_BRANCH}${GIT_BRANCH}${ResetColor}" @@ -292,18 +296,23 @@ function updatePrompt() { __chk_gitvar_status 'CLEAN' '-eq 1' - __add_status "$ResetColor$GIT_PROMPT_SUFFIX" - PS1="$LAST_COMMAND_INDICATOR$PROMPT_START$($prompt_callback)$STATUS$PROMPT_END" + NEW_PROMPT="$LAST_COMMAND_INDICATOR" if [[ -n "$VIRTUAL_ENV" ]]; then - PS1="($Blue$(basename \"$VIRTUAL_ENV\")$ResetColor) $PS1" + VENV=$(basename "${VIRTUAL_ENV}") + NEW_PROMPT="$NEW_PROMPT${GIT_PROMPT_VIRTUALENV/_VIRTUALENV_/${VENV}}" fi if [[ -n "$CONDA_DEFAULT_ENV" ]]; then - PS1="($Blue$(basename \"$CONDA_DEFAULT_ENV\")$ResetColor) $PS1" + VENV=$(basename "${CONDA_DEFAULT_ENV}") + NEW_PROMPT="$NEW_PROMPT${GIT_PROMPT_VIRTUALENV/_VIRTUALENV_/${VENV}}" fi + NEW_PROMPT="$NEW_PROMPT$PROMPT_START$($prompt_callback)$STATUS$PROMPT_END" else - PS1="$EMPTY_PROMPT" + NEW_PROMPT="$EMPTY_PROMPT" fi + + PS1="$NEW_PROMPT" } function prompt_callback_default {