Skip to content

Instantly share code, notes, and snippets.

@Honghe
Created December 27, 2021 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Honghe/bbd7936489548dc87336f84f70841767 to your computer and use it in GitHub Desktop.
Save Honghe/bbd7936489548dc87336f84f70841767 to your computer and use it in GitHub Desktop.
https://github.com/ohmybash/ font theme with conda venv prompt.
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