diff options
author | Dennis Eriksen <d@ennis.no> | 2023-10-22 11:13:27 +0300 |
---|---|---|
committer | Dennis Eriksen <d@ennis.no> | 2023-10-22 11:13:27 +0300 |
commit | 2625bb50cf52a6dbbf4eedfc0a0ec520b05c4aa6 (patch) | |
tree | a4b32089d0433856b49203a254ee7a5196fbd974 | |
parent | show user@host when root (diff) | |
download | adam3-2625bb50cf52a6dbbf4eedfc0a0ec520b05c4aa6.tar.gz |
Fix showing virtualenv
The time was misplaced when showing virtualenv on smaller screens.
Should be fixed now.
Also added a variable to change the color of the virtualenv
-rw-r--r-- | prompt_adam3_setup | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/prompt_adam3_setup b/prompt_adam3_setup index fb962b2..5e7c19a 100644 --- a/prompt_adam3_setup +++ b/prompt_adam3_setup @@ -20,12 +20,13 @@ PROMPT_ADAM3_COLOR1=multi # host-color. 'multi' means color changes w/hostname PROMPT_ADAM3_COLOR2=white,blue # user color PROMPT_ADAM3_COLOR3=39,none,1 # color for directory PROMPT_ADAM3_COLOR4=66 # color for time - # PROMPT_ADAM3_COLOR{1..4} accept comma-separated values for "foreground, - # background, bold". Fore- and background color takes both color names and - # color values. Bold can be set with 1 for bold, and 0 for not bold. For - # example, "blue,white,1" means bold white text on blue background. Values - # can be dropped from the right, so "blue,white" means blue text on white - # background, and "blue" means just blue text. +PROMTP_ADAM3_COLOR6=208 # virtualenv color + # PROMPT_ADAM3_COLOR{1,2,3,4,6} accept comma-separated values for + # "foreground, background, bold". Fore- and background color takes both + # color names and color values. Bold can be set with 1 for bold, and 0 for + # not bold. For example, "blue,white,1" means bold white text on blue + # background. Values can be dropped from the right, so "blue,white" means + # blue text on white background, and "blue" means just blue text. PROMPT_ADAM3_COLOR5=white # default prompt-color. Only takes a single color. PROMPT_ADAM3_TIME= # Set to 'false' if you don't want time on RPS1 @@ -68,6 +69,7 @@ prompt_adam3_setup () { color[dirD]=${3:-${PROMPT_ADAM3_COLOR3:-39,none,1}} # dir (double mode) color color[time]=${4:-${PROMPT_ADAM3_TIME:-${PROMPT_ADAM3_COLOR4:-66}}} # time color color[char]=${5:-${PROMPT_ADAM3_COLOR5:-white}} # default promptchar-color + color[venv]=${6:-${PROMPT_ADAM3_COLOR6:-208}} # virtualenv color # Username @@ -87,6 +89,9 @@ prompt_adam3_setup () { # SHLVL prom[shlvl]=${PROMPT_ADAM3_SHLVL:-'%(10L.%F{58}%L%f .)'} + # venv + prom[venv]="%F{$color[venv]}(SUBSTITUTE)%f" + # Promptchar (including exitcode) typeset -g PROMPT_ADAM3_PROMPTCHAR=${PROMPT_ADAM3_PROMPTCHAR:-"%(?..[%F{red}%?%f] )%B%F{%(!.red.$color[char])}%#%f%b "} # same as above, but with $ instead of % as promptchar for unprivileged users @@ -143,11 +148,16 @@ prompt_adam3_setup () { # Make each prompt-part global typeset -g PROMPT_ADAM3_PS1 - [[ -n $SSH_CLIENT || -n $SSH_TTY || -n $SSH_CONNECTION || -n $PROMPT_ADAM3_AOUH || $UID == 0 ]] \ + + # Show user@host if using ssh, PROMPT_ADAM3_AOUH is set, or you are root + [[ -n $SSH_CLIENT || -n $SSH_TTY || -n $SSH_CONNECTION \ + || -n $PROMPT_ADAM3_AOUH || $UID == 0 ]] \ && PROMPT_ADAM3_PS1="$prom[user]$prom[host] " + typeset -g PROMPT_ADAM3_SLM_DIR=$prom[dirS] typeset -g PROMPT_ADAM3_DLM_DIR=$prom[dirD] typeset -g PROMPT_ADAM3_RPS1=$prom[shlvl]$prom[time] + typeset -g PROMPT_ADAM3_VENV=$prom[venv] # Set up hook add-zsh-hook precmd prompt_adam3_precmd @@ -159,8 +169,10 @@ prompt_adam3_precmd () { # vcs vcs_info #$vcs_info_msg_0_ - local prom - prom=$PROMPT_ADAM3_PS1 + local prom preprom + (( ${+VIRTUAL_ENV} )) && preprom="${PROMPT_ADAM3_VENV/SUBSTITUTE/${VIRTUAL_ENV:t}} " + preprom+=${PROMPT_ADAM3_PS1} + prom=${preprom} prom+=$PROMPT_ADAM3_SLM_DIR prom+=$vcs_info_msg_0_ prom+=$PROMPT_ADAM3_PROMPTCHAR @@ -172,7 +184,7 @@ prompt_adam3_precmd () { # If the prompt is over half the terminal, we go into multiline-mode. if (( prompt_length > ( COLUMNS / 2 ) )); then - prom=$PROMPT_ADAM3_PS1 # reset prompt + prom=$preprom # reset prompt prom+=$PROMPT_ADAM3_DLM_DIR # double-line-mode dir # We need to recalculate prompt_length to know where to put time @@ -191,7 +203,6 @@ prompt_adam3_precmd () { fi PS1=$prom - (( ${+VIRTUAL_ENV} )) && PS1="%F{208}(${VIRTUAL_ENV:t})%f ${PS1}" PS2="${PS1}%_> %b%f%k" PS3="${PS1}?# %b%f%k" |