From ba030ff55862a3fd196a481792aa5c16dc25efb5 Mon Sep 17 00:00:00 2001 From: stackcon <48369016+stackcon@users.noreply.github.com> Date: Tue, 20 May 2025 01:55:46 -0500 Subject: [PATCH] Update bash version - made more responsive by inlining some styles - removed unreachable PROMPT_COMMAND condition - sets terminal title - extended venv section with support for conda environments --- aphrodite.theme.sh | 59 +++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/aphrodite.theme.sh b/aphrodite.theme.sh index 37cce84..69933f3 100644 --- a/aphrodite.theme.sh +++ b/aphrodite.theme.sh @@ -16,46 +16,61 @@ export VIRTUAL_ENV_DISABLE_PROMPT=true +export CONDA_CHANGEPS1=false +__aphrodite_cyan="\[$(tput setaf 6)\]" +__aphrodite_white="\[$(tput setaf 7)\]" +__aphrodite_brightblack="\[$(tput setaf 8)\]" +__aphrodite_brightblue="\[$(tput setaf 12)\]" +__aphrodite_reset="\[$(tput sgr0)\]" +__aphrodite_raw_red=$(tput setaf 1) + +__aphrodite_git_dirty=$(tput setaf 11) +__aphrodite_git_clean=$(tput setaf 10) + __aphrodite_update_prompt_data() { local RETVAL=$? __aphrodite_venv='' [[ -n "$VIRTUAL_ENV" ]] && __aphrodite_venv=$(basename "$VIRTUAL_ENV") + [[ -n "$CONDA_PREFIX" ]] && __aphrodite_venv=$(basename "$CONDA_PREFIX") + [[ -n "${__aphrodite_venv}" ]] && __aphrodite_venv=$(printf '[%s] ' "${__aphrodite_venv}") __aphrodite_git='' - __aphrodite_git_color=$(tput setaf 10) # clean + __aphrodite_git_color=${__aphrodite_git_clean} # clean local git_branch=$(git --no-optional-locks rev-parse --abbrev-ref HEAD 2> /dev/null) if [[ -n "$git_branch" ]]; then - local git_status=$(git --no-optional-locks status --porcelain 2> /dev/null | tail -n 1) - [[ -n "$git_status" ]] && __aphrodite_git_color=$(tput setaf 11) # dirty + test -z "$(2>/dev/null git --no-optional-locks status --porcelain=v2 --untracked-files=no --ignored=no --ignore-submodules=all)" && __aphrodite_git_color=${__aphrodite_git_dirty} # dirty __aphrodite_git="‹${git_branch}›" fi - __aphrodite_prompt_symbol_color=$(tput sgr0) - [[ "$RETVAL" -ne 0 ]] && __aphrodite_prompt_symbol_color=$(tput setaf 1) + __aphrodite_prompt_symbol_color='' + [[ "$RETVAL" -ne 0 ]] && __aphrodite_prompt_symbol_color=${__aphrodite_raw_red} + # Terminal title + printf "\033]2;%s\007" "${PWD/#$HOME/\~}" return $RETVAL # to preserve retcode } - -if [[ -n "$git_branch" ]]; then - PROMPT_COMMAND="$PROMPT_COMMAND; __aphrodite_update_prompt_data" -else - PROMPT_COMMAND="__aphrodite_update_prompt_data" -fi - +PROMPT_COMMAND="__aphrodite_update_prompt_data" PS1='' -PS1+='\[$(tput setaf 7)\]$(echo -ne $__aphrodite_venv)\[$(tput sgr0)\]' -PS1+='\[$(tput setaf 6)\]\u' -PS1+='\[$(tput setaf 8)\]@' -PS1+='\[$(tput setaf 12)\]\h' -PS1+='\[$(tput setaf 8)\]:' -PS1+='\[$(tput sgr0)\]\w ' -PS1+='\[$(echo -ne $__aphrodite_git_color)\]$(echo -ne $__aphrodite_git)\[$(tput sgr0)\] ' -PS1+='\[$(tput setaf 8)\]\[$([[ -n "$APHRODITE_THEME_SHOW_TIME" ]] && echo -n "[\t]")\]\[$(tput sgr0)\]' -PS1+='\[$(tput sgr0)\]\n' -PS1+='\[$(echo -ne $__aphrodite_prompt_symbol_color)\]\$\[$(tput sgr0)\] ' +PS1+="${__aphrodite_white}\${__aphrodite_venv}${__aphrodite_reset}" +PS1+="${__aphrodite_cyan}\u" +PS1+="${__aphrodite_brightblack}@" +PS1+="${__aphrodite_brightblue}\h" +PS1+="${__aphrodite_brightblack}:" +PS1+="${__aphrodite_reset}\w " +## git +PS1+='\[$(echo -ne $__aphrodite_git_color)\]' +PS1+='$(echo -ne $__aphrodite_git)' +PS1+="${__aphrodite_reset} " +## time +PS1+="${__aphrodite_brightblack}" +PS1+='\[$([[ -n "$APHRODITE_THEME_SHOW_TIME" ]] && echo -n "[\t]")\]' +PS1+="${__aphrodite_reset}\n" +## prompt symbol +PS1+='\[$(echo -ne $__aphrodite_prompt_symbol_color)\]' +PS1+="\$${__aphrodite_reset} "