Skip to content

Conversation

@yilewang
Copy link

@yilewang yilewang commented Sep 28, 2025

User description

The dulcie theme doesn't support showing the conda/python virtual environment information. I modified the dulcie.theme.sh file to add the feature to the dulcie theme

The original dulcie theme:
image

The newer version of dulcie theme:

Screenshot 2025-09-27 193557

PR Type

Enhancement


Description

  • Add virtual environment display support to dulcie theme

  • Show conda/python environment names in prompt

  • Implement custom venv detection function

  • Update prompt formatting for both single/multi-line modes


Diagram Walkthrough

flowchart LR
  A["dulcie theme"] --> B["_dulcie_get_venv_name()"]
  B --> C["detect CONDA_DEFAULT_ENV"]
  B --> D["detect VIRTUAL_ENV"]
  C --> E["python_env_prompt"]
  D --> E
  E --> F["updated PS1 prompt"]
Loading

File Walkthrough

Relevant files
Enhancement
dulcie.theme.sh
Add virtual environment display functionality                       

themes/dulcie/dulcie.theme.sh

  • Added _dulcie_get_venv_name() function to detect conda/python virtual
    environments
  • Added OMB_PROMPT_SHOW_PYTHON_VENV configuration variable
  • Modified _omb_theme_PROMPT_COMMAND to include virtual environment name
    in prompt
  • Updated PS1 formatting for both single-line and multi-line modes to
    display venv info
  • Removed demo comments and fixed minor typo in SCM_THEME_PROMPT_DIRTY
+27/-13 

The dulcie theme doesn't support showing the conda/python virtual environment information. I modified the `dulcie.theme.sh` file to add the feature to the dulcie theme
@qodo-merge-for-open-source
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Typo in variable

In the updated dirty SCM prompt the reset variable appears as _om_prompt_reset_color (missing the 'b'). This likely breaks color resetting for dirty state and should be _omb_prompt_reset_color.

SCM_THEME_PROMPT_DIRTY=" ${_omb_prompt_brown}${_om_prompt_reset_color}"
SCM_THEME_PROMPT_CLEAN=" ${_omb_prompt_bold_green}${_omb_prompt_normal}"
Config toggle

OMB_PROMPT_SHOW_PYTHON_VENV is introduced but never used to conditionally render the venv segment. Consider honoring this flag to allow users to disable the feature.

# Configuration for Python/Conda virtual environments
OMB_PROMPT_SHOW_PYTHON_VENV=${OMB_PROMPT_SHOW_PYTHON_VENV:=true} # Keep this for consistency

function dulcie_color {
  echo -en "\[\e[38;5;${1}m\]"
}

function dulcie_background {
  echo -en "\[\e[48;5;${1}m\]"
}

# ADDED: A custom function to get the venv name without conflicts.
function _dulcie_get_venv_name() {
  if [[ -n "$CONDA_DEFAULT_ENV" ]]; then
    # For conda, the name is in this variable
    echo "$CONDA_DEFAULT_ENV"
  elif [[ -n "$VIRTUAL_ENV" ]]; then
    # For standard venv, the name is the last part of the path
    basename "$VIRTUAL_ENV"
  fi
}

function _omb_theme_PROMPT_COMMAND {
  # MODIFIED: Use our custom, non-conflicting function to get the venv name.
  local venv_name=$(_dulcie_get_venv_name)
  local python_env_prompt=""
  if [[ -n "$venv_name" ]]; then
    # MODIFIED: Added a space at the end of this string.
    python_env_prompt="(${_omb_prompt_olive}${venv_name}${_omb_prompt_normal}) "
  fi
Prompt spacing

The venv segment appends a trailing space inside the brackets; combined with surrounding spaces this might lead to double spaces in some modes. Verify spacing consistency for both single and multi-line prompts with and without SCM info.

local venv_name=$(_dulcie_get_venv_name)
local python_env_prompt=""
if [[ -n "$venv_name" ]]; then
  # MODIFIED: Added a space at the end of this string.
  python_env_prompt="(${_omb_prompt_olive}${venv_name}${_omb_prompt_normal}) "
fi

color_user_root=$(dulcie_color 169)
color_user_nonroot="${_omb_prompt_green}"
color_host_local=$(dulcie_color 230)
color_host_remote=$(dulcie_color 214)
color_rootdir=$(dulcie_color 117)
color_workingdir=$(dulcie_color 117)
background_scm=$(dulcie_background 238)

SCM_THEME_ROOT_SUFFIX="|$(scm_char) "

# Set colors
if [ "${DULCIE_COLOR}" -eq "1" ]; then
  if [[ $EUID -ne 0 ]]; then
    color_user="${color_user_nonroot}"
  else
    color_user="${color_user_root}"
  fi

  if [[ -n "${SSH_CLIENT}" ]]; then
    color_host="${color_host_remote}"
  else
    color_host="${color_host_local}"
  fi

  DULCIE_USER="${color_user}\u${_omb_prompt_reset_color}"
  DULCIE_HOST="${color_host}\h${_omb_prompt_reset_color}"
  DULCIE_WORKINGDIR="${color_workingdir}\W${_omb_prompt_reset_color}"
  DULCIE_PROMPTCHAR="${color_user}"'\$'"${_omb_prompt_reset_color}"

  SCM_THEME_PROMPT_DIRTY=" ${_omb_prompt_brown}${_om_prompt_reset_color}"
  SCM_THEME_PROMPT_CLEAN=" ${_omb_prompt_bold_green}${_omb_prompt_normal}"
  DULCIE_SCM_BACKGROUND="${background_scm}"
  DULCIE_SCM_DIR_COLOR="${color_rootdir}"
  SCM_THEME_ROOT_SUFFIX="${_omb_prompt_reset_color}${SCM_THEME_ROOT_SUFFIX}"
  SCM_THEME_PROMPT_DIRTY=" $(dulcie_color 1)${_omb_prompt_reset_color}"
  SCM_THEME_PROMPT_CLEAN=" $(dulcie_color 10)${_omb_prompt_reset_color}"
else
  DULCIE_USER='\u'
  DULCIE_HOST='\h'
  DULCIE_WORKINGDIR='\W'
  DULCIE_PROMPTCHAR='\$'

  DULCIE_SCM_BACKGROUND=""
  DULCIE_SCM_DIR_COLOR=""
  SCM_THEME_DIR_COLOR=""
  SCM_THEME_PROMPT_DIRTY=""
  SCM_THEME_PROMPT_CLEAN=""
fi

# Change terminal title
printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"

# Open the new terminal in the same directory
_omb_util_function_exists __vte_osc7 && __vte_osc7

if [[ "${DULCIE_MULTILINE}" -eq "1" ]]; then
  PS1="${_omb_prompt_reset_color}[${python_env_prompt}${DULCIE_USER}@${DULCIE_HOST}${_omb_prompt_reset_color} ${DULCIE_WORKINGDIR}]"
  if [[ "$(scm_prompt_info)" ]]; then
    SCM_THEME_PROMPT_PREFIX="${DULCIE_SCM_BACKGROUND}|${DULCIE_SCM_DIR_COLOR}"
    SCM_THEME_PROMPT_SUFFIX="|${_omb_prompt_normal}"
    PS1="$(scm_prompt_info)\n${PS1}"
  fi
else
  SCM_THEME_PROMPT_PREFIX=" |${DULCIE_SCM_DIR_COLOR}"
  SCM_THEME_PROMPT_SUFFIX="|${_omb_prompt_normal}"
  PS1="${_omb_prompt_reset_color}[${python_env_prompt}${DULCIE_USER}@${DULCIE_HOST} ${DULCIE_WORKINGDIR}$(scm_prompt_info)]"
fi
PS1="${PS1}${DULCIE_PROMPTCHAR} "

@yilewang yilewang changed the title (theme/dulcie) to add virtual environment display to dulcie theme (theme/dulcie) Add virtual environment information to dulcie theme Sep 28, 2025
@qodo-merge-for-open-source
Copy link

qodo-merge-for-open-source bot commented Sep 28, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

Category Suggestion                                                                                                                                    Impact
Possible issue
Fix typo in color variable
Suggestion Impact:The commit corrected the variable name in SCM_THEME_PROMPT_DIRTY exactly as suggested, fixing the typo.

code diff:

-    SCM_THEME_PROMPT_DIRTY=" ${_omb_prompt_brown}✗${_om_prompt_reset_color}"
+    SCM_THEME_PROMPT_DIRTY=" ${_omb_prompt_brown}✗${_omb_prompt_reset_color}"

Fix a typo in the _om_prompt_reset_color variable by changing it to
_omb_prompt_reset_color to prevent prompt rendering issues.

themes/dulcie/dulcie.theme.sh [71]

-SCM_THEME_PROMPT_DIRTY=" ${_omb_prompt_brown}✗${_om_prompt_reset_color}"
+SCM_THEME_PROMPT_DIRTY=" ${_omb_prompt_brown}✗${_omb_prompt_reset_color}"

[Suggestion processed]

Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies a typo (_om_prompt_reset_color) introduced in the PR that would cause a rendering bug in the shell prompt.

High
Respect configuration for virtual environment
Suggestion Impact:The commit modified the condition around displaying the virtual environment. Although the line appears malformed, it attempts to include the OMB_PROMPT_SHOW_PYTHON_VENV check alongside the existing venv_name check, reflecting the suggestion's intent.

code diff:

-  if [[ -n "$venv_name" ]]; then
-    # MODIFIED: Added a space at the end of this string.
+  if [[ -n "$venv_name" ]]; then[[ "$OMB_PROMPT_SHOW_PYTHON_VENV" = true && -n "$venv_name" ]]; then
     python_env_prompt="(${_omb_prompt_olive}${venv_name}${_omb_prompt_normal}) "
   fi

Update the conditional check to respect the OMB_PROMPT_SHOW_PYTHON_VENV
configuration setting when displaying the Python virtual environment.

themes/dulcie/dulcie.theme.sh [37-40]

-if [[ -n "$venv_name" ]]; then
+if [[ "$OMB_PROMPT_SHOW_PYTHON_VENV" = true && -n "$venv_name" ]]; then
   # MODIFIED: Added a space at the end of this string.
   python_env_prompt="(${_omb_prompt_olive}${venv_name}${_omb_prompt_normal}) "
 fi

[Suggestion processed]

Suggestion importance[1-10]: 8

__

Why: The suggestion correctly points out that the newly introduced configuration variable OMB_PROMPT_SHOW_PYTHON_VENV is not being used, which is a functional bug.

Medium
High-level
Use the standard python plugin

Instead of implementing a custom function _dulcie_get_venv_name to detect Python
virtual environments, the theme should use the virtual_env_prompt function from
the standard python plugin. This change will reduce code duplication and improve
maintainability.

Examples:

themes/dulcie/dulcie.theme.sh [23-40]
function _dulcie_get_venv_name() {
  if [[ -n "$CONDA_DEFAULT_ENV" ]]; then
    # For conda, the name is in this variable
    echo "$CONDA_DEFAULT_ENV"
  elif [[ -n "$VIRTUAL_ENV" ]]; then
    # For standard venv, the name is the last part of the path
    basename "$VIRTUAL_ENV"
  fi
}


 ... (clipped 8 lines)

Solution Walkthrough:

Before:

function _dulcie_get_venv_name() {
  if [[ -n "$CONDA_DEFAULT_ENV" ]]; then
    echo "$CONDA_DEFAULT_ENV"
  elif [[ -n "$VIRTUAL_ENV" ]]; then
    basename "$VIRTUAL_ENV"
  fi
}

function _omb_theme_PROMPT_COMMAND {
  local venv_name=$(_dulcie_get_venv_name)
  local python_env_prompt=""
  if [[ -n "$venv_name" ]]; then
    python_env_prompt="(${_omb_prompt_olive}${venv_name}${_omb_prompt_normal}) "
  fi
  # ...
  PS1="...${python_env_prompt}..."
}

After:

# The custom function _dulcie_get_venv_name is removed.
# Assumes the 'python' plugin is loaded.

function _omb_theme_PROMPT_COMMAND {
  # The python plugin provides the virtual_env_prompt function.
  # It returns a formatted string like "(my-env) " when a venv is active.
  local python_env_prompt=$(virtual_env_prompt)

  # ...
  PS1="...${python_env_prompt}..."
}
Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies that the PR duplicates functionality from the standard python plugin, and using the existing virtual_env_prompt function would improve maintainability and align with the framework's design.

Medium
General
Add missing color reset sequence
Suggestion Impact:The commit added a second PS1 assignment that includes the missing ${_omb_prompt_reset_color} after ${DULCIE_HOST}, matching the suggestion’s intent (though it oddly left the original line and concatenated both).

code diff:

-    PS1="${_omb_prompt_reset_color}[${python_env_prompt}${DULCIE_USER}@${DULCIE_HOST} ${DULCIE_WORKINGDIR}$(scm_prompt_info)]"
+    PS1="${_omb_prompt_reset_color}[${python_env_prompt}${DULCIE_USER}@${DULCIE_HOST} ${DULCIE_WORKINGDIR}$(scm_prompt_info)]"+PS1="${_omb_prompt_reset_color}[${python_env_prompt}${DULCIE_USER}@${DULCIE_HOST}${_omb_prompt_reset_color} ${DULCIE_WORKINGDIR}$(scm_prompt_info)]"
+

Add the missing ${_omb_prompt_reset_color} sequence between ${DULCIE_HOST} and
${DULCIE_WORKINGDIR} in the single-line prompt definition to fix a color
bleeding issue.

themes/dulcie/dulcie.theme.sh [107]

-PS1="${_omb_prompt_reset_color}[${python_env_prompt}${DULCIE_USER}@${DULCIE_HOST} ${DULCIE_WORKINGDIR}$(scm_prompt_info)]"
+PS1="${_omb_prompt_reset_color}[${python_env_prompt}${DULCIE_USER}@${DULCIE_HOST}${_omb_prompt_reset_color} ${DULCIE_WORKINGDIR}$(scm_prompt_info)]"

[Suggestion processed]

Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies a missing color reset sequence in the single-line prompt, which would cause an inconsistent color display.

Medium
  • Update

…olor reset sequence. The high-level issue suggested by the bot is not implemented because it is not working from my test. It will create errors when detecting venv
@yilewang
Copy link
Author

#714 This pull request aims to solve this closed issue before.

# [ritola@localhost ~]$ cd .bash-it/themes/dulcie
# [ritola@localhost |master ✓| dulcie]$ # This is single line mode
# |bash-it|± master ✓|
# [ritola@localhost dulcie]$ # In multi line, the SCM info is in the separate line
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why were they removed? Are there problems with these descriptions?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to apologize for it. No problem for these descriptions. My initial intention was to make my codes run but ignore the fact that I need to ensure I only made minimal and meaningful changes to the original codebase. I added them back in my new commit.

DULCIE_MULTILINE=${DULCIE_MULTILINE:=1} # 0 = Single line, 1 = SCM in separate line

# Configuration for Python/Conda virtual environments
OMB_PROMPT_SHOW_PYTHON_VENV=${OMB_PROMPT_SHOW_PYTHON_VENV:=true} # Keep this for consistency
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
OMB_PROMPT_SHOW_PYTHON_VENV=${OMB_PROMPT_SHOW_PYTHON_VENV:=true} # Keep this for consistency
OMB_PROMPT_SHOW_PYTHON_VENV=${OMB_PROMPT_SHOW_PYTHON_VENV:=false} # Keep this for consistency

This line is usually put to keep the old behavior for existing users. We haven't been showing the Python environment information in the prompt, so we should keep the default behavior to be not showing it and let the user opt-in the Python environment information by setting OMB_PROMPT_SHOW_PYTHON_VENV in ~/.bashrc explicitly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed! now the default is false.

echo -en "\[\e[48;5;${1}m\]"
}

function _dulcie_get_venv_name() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMB_PROMPT_SHOW_PYTHON_VENV is meant for the prompt segment generated by _omb_prompt_get_python_venv():

function _omb_prompt_get_python_venv {
python_venv=
[[ ${OMB_PROMPT_SHOW_PYTHON_VENV-} == true ]] || return 1

Please use _omb_prompt_get_python_venv instead of defining a function doing the same thing as the existing one.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed! the customized function was deleted.

fi
else
SCM_THEME_PROMPT_PREFIX=" ${DULCIE_SCM_BACKGROUND}|${DULCIE_SCM_DIR_COLOR}"
SCM_THEME_PROMPT_PREFIX=" |${DULCIE_SCM_DIR_COLOR}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed. It should not be removed. I added them back

SCM_THEME_PROMPT_PREFIX=" |${DULCIE_SCM_DIR_COLOR}"
SCM_THEME_PROMPT_SUFFIX="|${_omb_prompt_normal}"
PS1="${_omb_prompt_reset_color}[${DULCIE_USER}@${DULCIE_HOST}$(scm_prompt_info)${_omb_prompt_reset_color} ${DULCIE_WORKINGDIR}]"
PS1="${_omb_prompt_reset_color}[${python_env_prompt}${DULCIE_USER}@${DULCIE_HOST} ${DULCIE_WORKINGDIR}$(scm_prompt_info)]"+PS1="${_omb_prompt_reset_color}[${python_env_prompt}${DULCIE_USER}@${DULCIE_HOST}${_omb_prompt_reset_color} ${DULCIE_WORKINGDIR}$(scm_prompt_info)]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is broken.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for pointing it out. I have fixed this code. No extra edits in addition to adding the venv info to the prompt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants