28dc8c58ef14325d94feb7f34616839c7975e7d0

Author
Marc Cornellà <hello@mcornella.com>
Committer
Marc Cornellà <hello@mcornella.com>
Date

Message

refactor(michelebologna): simplify and clean up code

Diff

 1diff --git a/themes/michelebologna.zsh-theme b/themes/michelebologna.zsh-theme
 2index bb567b3d8bf3f38491cc80ed3a46900b003a8c72..bb86d68db074514d33ad4d5c3d5360f5d3865009 100644
 3--- a/themes/michelebologna.zsh-theme
 4+++ b/themes/michelebologna.zsh-theme
 5@@ -35,23 +35,17 @@ local reset="%{$reset_color%}"
 6 local -a color_array
 7 color_array=($green $red $cyan $yellow $blue $magenta $white)
 8 
 9-local username_normal_color=$white
10-local username_root_color=$red
11-local hostname_root_color=$red
12-
13-# calculating hostname color with hostname characters
14-for i in $HOST; local hostname_normal_color=$color_array[$[((#i))%7+1]]
15-local -a hostname_color
16-hostname_color=%(!.$hostname_root_color.$hostname_normal_color)
17-
18+local username_color=$white
19+local hostname_color=$color_array[$[((#HOST))%7+1]] # choose hostname color based on first character
20 local current_dir_color=$blue
21-local username_command="%n"
22-local hostname_command="%m"
23+
24+local username="%n"
25+local hostname="%m"
26 local current_dir="%~"
27 
28-local username_output="%(!..$username_normal_color$username_command$reset@)"
29-local hostname_output="$hostname_color$hostname_command$reset"
30-local current_dir_output="$current_dir_color$current_dir$reset"
31+local username_output="%(!..${username_color}${username}${reset}@)"
32+local hostname_output="${hostname_color}${hostname}${reset}"
33+local current_dir_output="${current_dir_color}${current_dir}${reset}"
34 local jobs_bg="${red}fg: %j$reset"
35 local last_command_output="%(?.%(!.$red.$green).$yellow)"
36 
37@@ -68,8 +62,18 @@ ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE=">"
38 ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE="<"
39 ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE="$red<>"
40 
41-PROMPT='$username_output$hostname_output:$current_dir_output%1(j. [$jobs_bg].)'
42-GIT_PROMPT='$(out=$(git_prompt_info)$(git_prompt_status)$(git_remote_status);if [[ -n $out ]]; then printf %s " $white($green$out$white)$reset";fi)'
43-PROMPT+="$GIT_PROMPT"
44+function michelebologna_git_prompt {
45+  local out=$(git_prompt_info)$(git_prompt_status)$(git_remote_status)
46+  [[ -n $out ]] || return
47+  printf " %s(%s%s%s)%s" \
48+    "%{$fg_bold[white]%}" \
49+    "%{$fg_bold[green]%}" \
50+    "$out" \
51+    "%{$fg_bold[white]%}" \
52+    "%{$reset_color%}"
53+}
54+
55+PROMPT="$username_output$hostname_output:$current_dir_output%1(j. [$jobs_bg].)"
56+PROMPT+='$(michelebologna_git_prompt)'
57 PROMPT+=" $last_command_output%#$reset "
58 RPROMPT=''