Created
December 27, 2021 03:01
-
-
Save Honghe/bbd7936489548dc87336f84f70841767 to your computer and use it in GitHub Desktop.
https://github.com/ohmybash/ font theme with conda venv prompt.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/themes/font/font.theme.sh b/themes/font/font.theme.sh | |
index c691e57..5a9dcc3 100644 | |
--- a/themes/font/font.theme.sh | |
+++ b/themes/font/font.theme.sh | |
@@ -37,12 +37,23 @@ THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%I:%M:%S"} | |
VIRTUALENV_THEME_PROMPT_PREFIX='(' | |
VIRTUALENV_THEME_PROMPT_SUFFIX=') ' | |
+function _python_venv_prompt { | |
+ local python_venv="" | |
+ | |
+ if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then | |
+ python_venv="${CONDA_DEFAULT_ENV}" | |
+ elif [[ -n "${VIRTUAL_ENV}" ]]; then | |
+ python_venv=$(basename "${VIRTUAL_ENV}") | |
+ fi | |
+ [[ -n "${python_venv}" ]] && echo -e "$VIRTUALENV_THEME_PROMPT_PREFIX$python_venv$VIRTUALENV_THEME_PROMPT_SUFFIX" | |
+} | |
+ | |
function prompt_command() { | |
# This needs to be first to save last command return code | |
local RC="$?" | |
hostname="${bold_black}\u@\h" | |
- virtualenv="${white}$(virtualenv_prompt)" | |
+ virtualenv="${white}$(_python_venv_prompt)" | |
# Set return status color | |
if [[ ${RC} == 0 ]]; then | |
@@ -54,7 +65,7 @@ function prompt_command() { | |
# Append new history lines to history file | |
history -a | |
- PS1="$(clock_prompt)${virtualenv}${hostname} ${bold_cyan}\W $(scm_prompt_char_info)${ret_status}→ ${normal}" | |
+ PS1="${virtualenv}${hostname} ${bold_cyan}\W $(scm_prompt_char_info)${ret_status}→ ${normal}" | |
} | |
safe_append_prompt_command prompt_command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment