From 7312c868b3c88c337ea2b8e09c8e99dfa4e64f6c Mon Sep 17 00:00:00 2001 From: bretello Date: Fri, 5 Apr 2024 13:08:21 +0200 Subject: [PATCH] zsh: theme: avoid using functions where possible includes fix for ohmyzsh's breaking change in ec1afe9d (async prompt) --- themes/brethil-minimal.zsh-theme | 2 ++ themes/brethil.zsh-theme | 51 ++++++++++---------------------- 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/themes/brethil-minimal.zsh-theme b/themes/brethil-minimal.zsh-theme index be32ab2..ab1d585 100644 --- a/themes/brethil-minimal.zsh-theme +++ b/themes/brethil-minimal.zsh-theme @@ -1,3 +1,5 @@ +# vim:ft=zsh ts=2 sw=2 sts=2 + local ret_status="%(?:%{$fg_bold[green]%}➜%{$reset_color%}:%{$fg[red]%}➜%{$reset_color%})" local user="%(#:root@:)" PROMPT='[%{$fg[red]%}${user}%M%{$reset_color%}][:%{$fg[green]%}%c%{$reset_color%}]$(git_prompt_info) ${ret_status} ' diff --git a/themes/brethil.zsh-theme b/themes/brethil.zsh-theme index 72e2d7f..e2e4839 100644 --- a/themes/brethil.zsh-theme +++ b/themes/brethil.zsh-theme @@ -18,10 +18,7 @@ function user_prompt(){ fi } -function job_prompt() { - # Shows jobs number on an orange background if there are background jobs - echo "%(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) @@ -32,14 +29,13 @@ function shlvl_prompt() { fi } -function path_prompt(){ - # Shows last 3 items in path if there are more than 4 - echo "[%F{green}%(4~:…/%3~:%~)%f]" -} +# TODO: add truncation using +# Shows last 3 items in path if there are more than 4 +local path_prompt='[%F{green}%(4~:…/%3~:%~)%f]' # PREFIX/SUFFIX are added before/after `git_prompt_info` -ZSH_THEME_GIT_PROMPT_PREFIX="%f%{$fg[yellow]%} " -ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_PREFIX=" %f%{$fg[yellow]%} " +ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} |" ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[white]%}%{$fg[red]%}x%{$reset_color%}" ZSH_THEME_GIT_PROMPT_CLEAN=" %{$fg[white]%}%{$fg[green]%}√%{$reset_color%}" @@ -75,39 +71,24 @@ function virtualenv_info { echo -n " $BOLD_PURPLE<$venv>$CLEAR " } -function git_prompt() { - # prints git info if in a git repo - if ! git rev-parse --git-dir &>/dev/null; then - return - fi - echo " $(git_prompt_info) |$(git_prompt_status)$(git_remote_status)" -} +local git_prompt='$(git_prompt_info)$(git_prompt_status)$(git_remote_status)' +local return_code_RPS1='%(?..%B%F{88}-$?-%f%b)' -function return_code_RPS1() { - # red status code if last exit code is non-zero - echo "%(?..%B%F{88}-$?-%f%b)" -} +local success="%B%F{28} →%f%b" +local failure="%B%{$fg[red]%} x%b%{$reset_color%}" +local prompt_with_previous_return_status="%(?:$success:$failure) " -function prompt_with_previous_return_status() { - local success="%B%F{28} →%f%b" - local failure="%B%{$fg[red]%} x%b%{$reset_color%}" - echo "%(?:$success:$failure)" -} - - -function prompt_too_long(){ - # prints a newline if more than $COLUMNS/2 characters have been printed - local newline=$'\n' - echo "%-$((COLUMNS/2))(l..${newline})" -} +# prints a newline if more than $COLUMNS/2 characters have been printed, see end of `man zshmisc` +local prompt_too_long='%-$((COLUMNS/2))(l..'$'\n'')' ## oh-my-zsh vi-mode plugins indicators: export MODE_INDICATOR="[%B%K{red}nav%k%b]" # red background export INSERT_MODE_INDICATOR="[%B%K{28}ins%k%b]" # green background -PROMPT='$(virtualenv_info)$(user_prompt)$(path_prompt)$(git_prompt)$(job_prompt)$(shlvl_prompt)$(prompt_too_long)$(prompt_with_previous_return_status) ' +# 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}" # Right prompt is just return code and time -RPS1='$(return_code_RPS1)$(vi_mode_prompt_info)[%*]' +RPS1="${return_code_RPS1}"'$(vi_mode_prompt_info)[%*]'