Parent directory

michelebologna.zsh-theme

2758 bytes
 1# Michele Bologna's theme
 2# https://www.michelebologna.net
 3#
 4# This a theme for oh-my-zsh. Features a colored prompt with:
 5# * username@host: [jobs] [git] workdir %
 6# * hostname color is based on hostname characters. When using as root, the
 7# prompt shows only the hostname in red color.
 8# * [jobs], if applicable, counts the number of suspended jobs tty
 9# * [git], if applicable, represents the status of your git repo (more on that
10# later)
11# * '%' prompt will be green if last command return value is 0, yellow otherwise.
12#
13# git prompt is inspired by official git contrib prompt:
14# https://github.com/git/git/tree/master/contrib/completion/git-prompt.sh
15# and it adds:
16# * the current branch
17# * '%' if there are untracked files
18# * '$' if there are stashed changes
19# * '*' if there are modified files
20# * '+' if there are added files
21# * '<' if local repo is behind remote repo
22# * '>' if local repo is ahead remote repo
23# * '=' if local repo is equal to remote repo (in sync)
24# * '<>' if local repo is diverged
25
26local green="%{$fg_bold[green]%}"
27local red="%{$fg_bold[red]%}"
28local cyan="%{$fg_bold[cyan]%}"
29local yellow="%{$fg_bold[yellow]%}"
30local blue="%{$fg_bold[blue]%}"
31local magenta="%{$fg_bold[magenta]%}"
32local reset="%{$reset_color%}"
33
34local -a color_array=($green $red $cyan $yellow $blue $magenta)
35
36local username_color=$blue
37local hostname_color=$color_array[$(( (#HOST) % 6 + 1 ))] # choose hostname color based on first character
38local current_dir_color=$blue
39
40local username="%n"
41local hostname="%m"
42local current_dir="%~"
43
44local username_output="%(!..${username_color}${username}${reset}@)"
45local hostname_output="${hostname_color}${hostname}${reset}"
46local current_dir_output="${current_dir_color}${current_dir}${reset}"
47local jobs_bg="${red}jobs: %j$reset"
48local last_command_output="%(?.%(!.$red.$green).$yellow)"
49
50ZSH_THEME_GIT_PROMPT_PREFIX=""
51ZSH_THEME_GIT_PROMPT_SUFFIX=""
52ZSH_THEME_GIT_PROMPT_DIRTY=""
53ZSH_THEME_GIT_PROMPT_CLEAN=""
54ZSH_THEME_GIT_PROMPT_UNTRACKED="$blue%%"
55ZSH_THEME_GIT_PROMPT_MODIFIED="$red*"
56ZSH_THEME_GIT_PROMPT_ADDED="$green+"
57ZSH_THEME_GIT_PROMPT_STASHED="${blue}\$"
58ZSH_THEME_GIT_PROMPT_EQUAL_REMOTE="$green="
59ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE="${green}>"
60ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE="${yellow}<"
61ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE="$red<>"
62
63function michelebologna_git_prompt {
64  local out=$(git_prompt_info)$(git_prompt_status)$(git_remote_status)
65  [[ -n $out ]] || return
66  printf " %s(%s%s%s)%s" \
67    "%{$fg_bold[blue]%}" \
68    "%{$fg_bold[green]%}" \
69    "$out" \
70    "%{$fg_bold[blue]%}" \
71    "%{$reset_color%}"
72}
73
74PROMPT="$username_output$hostname_output:$current_dir_output%1(j. [$jobs_bg].)"
75PROMPT+='$(michelebologna_git_prompt)'
76PROMPT+=" $last_command_output%#$reset "
77RPROMPT=''