1
0
mirror of https://git.decapod.one/brethil/dotfiles synced 2024-11-22 03:21:30 +01:00

zsh: theme: get rid of more functions

This commit is contained in:
bretello 2024-04-09 16:59:12 +02:00
parent 81d8c56836
commit 030903dcd7
Signed by: brethil
GPG Key ID: 876AAC6290170FE7

View File

@ -3,33 +3,31 @@
# See "EXPANSION OF PROMPT SEQUENCES" in `man zshmisc` # See "EXPANSION OF PROMPT SEQUENCES" in `man zshmisc`
# Note: Most of the expansions/color sequences can be tested using `print -P` # Note: Most of the expansions/color sequences can be tested using `print -P`
function user_prompt(){
# prints hostname on an orange background if on an ssh connection, adds username if root # prints hostname on an orange background if on an ssh connection, adds username if root
local user='%(!.%K{160}%F{255}%B%n%b%k%f.)' # prints 'root' on a red background if user is root local user='%(!.%K{160}%F{255}%B%n%b%k%f.)' # prints 'root' on a red background if user is root
local host='%K{202}%B%F{255}%m%f%k%b' # bold host name on an orange background local host='%K{202}%B%F{255}%m%f%k%b' # bold host name on an orange background
local open_bracket='%(!.[.)' local open_bracket='%(!.[.)'
local close_bracket='%(!.].)' local close_bracket='%(!.].)'
local at='%(!.@.)' local at='%(!.@.)'
if [[ -n $SSH_CONNECTION ]]; then local user_prompt
echo "[${user}${at}${host}]" if [[ -n $SSH_CONNECTION ]]; then
else user_prompt="[${user}${at}${host}]"
echo "${open_bracket}${user}${close_bracket}" else
fi user_prompt="${open_bracket}${user}${close_bracket}"
} fi
local job_prompt="%(1j.%B%K{202}%F{220} %j %k%b.)" local job_prompt="%(1j.%B%K{202}%F{220} %j %k%b.)"
function shlvl_prompt() {
# Shows SHLVL on a magenta background if SHLVL > 1 (2 if in a tmux session)
if [[ -z "$TMUX" ]]; then
echo "%(2L.%K{161}%F{255}%B %L %f%b%k.)"
else
echo "%(3L.%K{161}%F{255}%B $((SHLVL-1)) %f%b%k.)"
fi
}
# TODO: add truncation using local shlvl_prompt
# Shows SHLVL on a magenta background if SHLVL > 1 (2 if in a tmux session)
if [[ -z "$TMUX" ]]; then
shlvl_prompt="%(2L.%K{161}%F{255}%B %L %f%b%k.)"
else
shlvl_prompt="%(3L.%K{161}%F{255}%B $((SHLVL-1)) %f%b%k.)"
fi
# Shows last 3 items in path if there are more than 4 # Shows last 3 items in path if there are more than 4
local path_prompt='[%F{green}%(4~:…/%3~:%~)%f]' local path_prompt='[%F{green}%(4~:…/%3~:%~)%f]'
@ -57,12 +55,12 @@ ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE=">"
ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE="<" ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE="<"
ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE="<>" ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE="<>"
local BOLD_PURPLE='%B%F{5}'
local CLEAR='%f%b'
local venv
function virtualenv_info { function virtualenv_info {
[ -z "$VIRTUAL_ENV" ] && return [ -z "$VIRTUAL_ENV" ] && return
local BOLD_PURPLE='%B%F{5}'
local CLEAR='%f%b'
local venv
venv="$(basename "$VIRTUAL_ENV")" venv="$(basename "$VIRTUAL_ENV")"
if [[ "$venv" == ".venv" ]]; then if [[ "$venv" == ".venv" ]]; then
venv="$(basename $(dirname "$VIRTUAL_ENV") )" venv="$(basename $(dirname "$VIRTUAL_ENV") )"
@ -88,7 +86,7 @@ export MODE_INDICATOR="[%B%K{red}nav%k%b]" # red background
export INSERT_MODE_INDICATOR="[%B%K{28}ins%k%b]" # green background export INSERT_MODE_INDICATOR="[%B%K{28}ins%k%b]" # green background
# put it all together # put it all together
PROMPT='$(virtualenv_info)$(user_prompt)'"${path_prompt}${git_prompt}${job_prompt}"'$(shlvl_prompt)'"${prompt_too_long}${prompt_with_previous_return_status}" PROMPT='$(virtualenv_info)'"${user_prompt}${path_prompt}${git_prompt}${job_prompt}${shlvl_prompt}${prompt_too_long}${prompt_with_previous_return_status}"
# Right prompt is just return code and time # Right prompt is just return code and time
RPS1="${return_code_RPS1}"'$(vi_mode_prompt_info)[%*]' RPS1="${return_code_RPS1}"'$(vi_mode_prompt_info)[%*]'