From 28dc8c58ef14325d94feb7f34616839c7975e7d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Wed, 23 Feb 2022 19:55:33 +0100 Subject: [PATCH] refactor(michelebologna): simplify and clean up code --- themes/michelebologna.zsh-theme | 38 ++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/themes/michelebologna.zsh-theme b/themes/michelebologna.zsh-theme index bb567b3d8..bb86d68db 100644 --- a/themes/michelebologna.zsh-theme +++ b/themes/michelebologna.zsh-theme @@ -35,23 +35,17 @@ local reset="%{$reset_color%}" local -a color_array color_array=($green $red $cyan $yellow $blue $magenta $white) -local username_normal_color=$white -local username_root_color=$red -local hostname_root_color=$red - -# calculating hostname color with hostname characters -for i in $HOST; local hostname_normal_color=$color_array[$[((#i))%7+1]] -local -a hostname_color -hostname_color=%(!.$hostname_root_color.$hostname_normal_color) - +local username_color=$white +local hostname_color=$color_array[$[((#HOST))%7+1]] # choose hostname color based on first character local current_dir_color=$blue -local username_command="%n" -local hostname_command="%m" + +local username="%n" +local hostname="%m" local current_dir="%~" -local username_output="%(!..$username_normal_color$username_command$reset@)" -local hostname_output="$hostname_color$hostname_command$reset" -local current_dir_output="$current_dir_color$current_dir$reset" +local username_output="%(!..${username_color}${username}${reset}@)" +local hostname_output="${hostname_color}${hostname}${reset}" +local current_dir_output="${current_dir_color}${current_dir}${reset}" local jobs_bg="${red}fg: %j$reset" local last_command_output="%(?.%(!.$red.$green).$yellow)" @@ -68,8 +62,18 @@ ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE=">" ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE="<" ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE="$red<>" -PROMPT='$username_output$hostname_output:$current_dir_output%1(j. [$jobs_bg].)' -GIT_PROMPT='$(out=$(git_prompt_info)$(git_prompt_status)$(git_remote_status);if [[ -n $out ]]; then printf %s " $white($green$out$white)$reset";fi)' -PROMPT+="$GIT_PROMPT" +function michelebologna_git_prompt { + local out=$(git_prompt_info)$(git_prompt_status)$(git_remote_status) + [[ -n $out ]] || return + printf " %s(%s%s%s)%s" \ + "%{$fg_bold[white]%}" \ + "%{$fg_bold[green]%}" \ + "$out" \ + "%{$fg_bold[white]%}" \ + "%{$reset_color%}" +} + +PROMPT="$username_output$hostname_output:$current_dir_output%1(j. [$jobs_bg].)" +PROMPT+='$(michelebologna_git_prompt)' PROMPT+=" $last_command_output%#$reset " RPROMPT=''