feat(essembeh): update theme with new features (#9595)
- single line
- quite simple by default: user@host:$PWD
- green for local shell as non root
- red for ssh shell as non root
- magenta for root sessions
- prefix with remote address for ssh shells
- prefix to detect docker containers or chroot
- git plugin to display current branch and status
Diff
1diff --git a/themes/essembeh.zsh-theme b/themes/essembeh.zsh-theme
2index 939bb7a4cc39614c8ddf61a83ecbced2686ed158..f34f36f8a3a51dd9e421feeeec0e4b6e476bdd19 100644
3--- a/themes/essembeh.zsh-theme
4+++ b/themes/essembeh.zsh-theme
5@@ -1,24 +1,14 @@
6-# Theme with full path names and hostname
7-# Handy if you work on different servers all the time;
8-
9-local return_code="%(?..%{$fg_bold[red]%}%? ↵%{$reset_color%})"
10-
11-function my_git_prompt_info() {
12- ref=$(git symbolic-ref HEAD 2> /dev/null) || return
13- GIT_STATUS=$(git_prompt_status)
14- [[ -n $GIT_STATUS ]] && GIT_STATUS=" $GIT_STATUS"
15- echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$GIT_STATUS$ZSH_THEME_GIT_PROMPT_SUFFIX"
16-}
17-
18-# Colored prompt
19-ZSH_THEME_COLOR_USER="green"
20-ZSH_THEME_COLOR_HOST="green"
21-ZSH_THEME_COLOR_PWD="yellow"
22-test -n "$SSH_CONNECTION" && ZSH_THEME_COLOR_USER="red" && ZSH_THEME_COLOR_HOST="red"
23-test `id -u` = 0 && ZSH_THEME_COLOR_USER="magenta" && ZSH_THEME_COLOR_HOST="magenta"
24-PROMPT='%{$fg_bold[$ZSH_THEME_COLOR_USER]%}%n@%{$fg_bold[$ZSH_THEME_COLOR_HOST]%}%M%{$reset_color%}:%{$fg_bold[$ZSH_THEME_COLOR_PWD]%}%~%{$reset_color%} $(my_git_prompt_info)%(!.#.$) '
25-RPS1="${return_code}"
26+# My custom theme:
27+# - single line
28+# - quite simple by default: user@host:$PWD
29+# - green for local shell as non root
30+# - red for ssh shell as non root
31+# - magenta for root sessions
32+# - prefix with remote address for ssh shells
33+# - prefix to detect docker containers or chroot
34+# - git plugin to display current branch and status
3536+# git plugin
37 ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[cyan]%}("
38 ZSH_THEME_GIT_PROMPT_SUFFIX=") %{$reset_color%}"
39 ZSH_THEME_GIT_PROMPT_UNTRACKED="%%"
40@@ -28,3 +18,33 @@ ZSH_THEME_GIT_PROMPT_RENAMED="~"
41 ZSH_THEME_GIT_PROMPT_DELETED="!"
42 ZSH_THEME_GIT_PROMPT_UNMERGED="?"
4344+function zsh_essembeh_gitstatus {
45+ ref=$(git symbolic-ref HEAD 2> /dev/null) || return
46+ GIT_STATUS=$(git_prompt_status)
47+ if [[ -n $GIT_STATUS ]]; then
48+ GIT_STATUS=" $GIT_STATUS"
49+ fi
50+ echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$GIT_STATUS$ZSH_THEME_GIT_PROMPT_SUFFIX"
51+}
52+
53+# by default, use green for user@host and no prefix
54+local ZSH_ESSEMBEH_COLOR="green"
55+local ZSH_ESSEMBEH_PREFIX=""
56+if [[ -n "$SSH_CONNECTION" ]]; then
57+ # display the source address if connected via ssh
58+ ZSH_ESSEMBEH_PREFIX="%{$fg[yellow]%}[$(echo $SSH_CONNECTION | awk '{print $1}')]%{$reset_color%} "
59+ # use red color to highlight a remote connection
60+ ZSH_ESSEMBEH_COLOR="red"
61+elif [[ -r /etc/debian_chroot ]]; then
62+ # prefix prompt in case of chroot
63+ ZSH_ESSEMBEH_PREFIX="%{$fg[yellow]%}[chroot:$(cat /etc/debian_chroot)]%{$reset_color%} "
64+elif [[ -r /.dockerenv ]]; then
65+ # also prefix prompt inside a docker contrainer
66+ ZSH_ESSEMBEH_PREFIX="%{$fg[yellow]%}[docker]%{$reset_color%} "
67+fi
68+if [[ $UID = 0 ]]; then
69+ # always use magenta for root sessions, even in ssh
70+ ZSH_ESSEMBEH_COLOR="magenta"
71+fi
72+PROMPT='${ZSH_ESSEMBEH_PREFIX}%{$fg[$ZSH_ESSEMBEH_COLOR]%}%n@%M%{$reset_color%}:%{%B$fg[yellow]%}%~%{$reset_color%b%} $(zsh_essembeh_gitstatus)%(!.#.$) '
73+RPROMPT="%(?..%{$fg[red]%}%?%{$reset_color%})"