From 4ca0a7ce8b6a6210f80225396da7928e1f1a36ff Mon Sep 17 00:00:00 2001 From: "thomas.kopp" Date: Mon, 19 Oct 2026 00:59:24 +0200 Subject: [PATCH] feat(zsh): ys-style gruvbox prompt on servers instead of p10k Thomas prefers the two-line ys layout root already had. user@host in gruvbox red (a red block for root) marks the machine. Shared file so root's shell can use a root-owned copy. Co-Authored-By: Claude Opus 5.5 --- .config/zsh/p10k-server.zsh | 52 --------------------------------- .config/zsh/rc.d/05-pre-omz.zsh | 6 +++- .config/zsh/rc.d/50-server.zsh | 11 ++----- .config/zsh/server-prompt.zsh | 31 ++++++++++++++++++++ 4 files changed, 39 insertions(+), 61 deletions(-) delete mode 100644 .config/zsh/p10k-server.zsh create mode 100644 .config/zsh/server-prompt.zsh diff --git a/.config/zsh/p10k-server.zsh b/.config/zsh/p10k-server.zsh deleted file mode 100644 index 77820e5..0000000 --- a/.config/zsh/p10k-server.zsh +++ /dev/null @@ -1,52 +0,0 @@ -# powerlevel10k configuration for the server role. -# -# Deliberately not the wizard's output. A server is reached from whatever -# terminal happens to be at hand, so this uses ASCII rather than the icon set -# that assumes a Nerd Font, and keeps the segment list short enough to read at -# a glance during an incident. -# -# Sourced from 50-server.zsh, which runs after oh-my-zsh has loaded -# powerlevel10k - the same point in the sequence at which p10k expects its own -# ~/.p10k.zsh. beastix keeps its own file and is untouched by this. - -# No glyphs. The prompt has to be legible from a phone terminal too. -typeset -g POWERLEVEL9K_MODE=ascii -typeset -g POWERLEVEL9K_ICON_PADDING=none - -# One line, no frame. Nothing decorative survives being read in a hurry. -typeset -g POWERLEVEL9K_PROMPT_ON_NEWLINE=false -typeset -g POWERLEVEL9K_RPROMPT_ON_NEWLINE=false -typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir vcs prompt_char) -typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status command_execution_time time) - -# The point of the whole exercise: user@host, always, in red. shron carries -# mail, web and cloud, and the prompt should answer "which machine is this" -# before the next command is typed. -typeset -g POWERLEVEL9K_ALWAYS_SHOW_CONTEXT=true -typeset -g POWERLEVEL9K_ALWAYS_SHOW_USER=true -typeset -g POWERLEVEL9K_CONTEXT_TEMPLATE='%n@%m' -# -# Fixed 256-colour indices, not the named ANSI colours. Terminal themes remap -# the first 16 freely - under gruvbox "white" is a mid grey and "blue" a muted -# teal, which left the text barely legible. 231 is pure white; 124 and 24 are -# dark enough to give it roughly 7:1 contrast on either segment. -typeset -g POWERLEVEL9K_CONTEXT_BACKGROUND=124 -typeset -g POWERLEVEL9K_CONTEXT_FOREGROUND=231 -typeset -g POWERLEVEL9K_CONTEXT_DEFAULT_BACKGROUND=124 -typeset -g POWERLEVEL9K_CONTEXT_DEFAULT_FOREGROUND=231 -typeset -g POWERLEVEL9K_CONTEXT_ROOT_BACKGROUND=124 -typeset -g POWERLEVEL9K_CONTEXT_ROOT_FOREGROUND=226 - -typeset -g POWERLEVEL9K_DIR_BACKGROUND=24 -typeset -g POWERLEVEL9K_DIR_FOREGROUND=231 -typeset -g POWERLEVEL9K_DIR_SHORTENED_FOREGROUND=252 -typeset -g POWERLEVEL9K_DIR_ANCHOR_FOREGROUND=231 -typeset -g POWERLEVEL9K_SHORTEN_STRATEGY=truncate_to_unique - -# Only mention how long something took when it was long enough to notice. -typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=3 -typeset -g POWERLEVEL9K_TIME_FORMAT='%D{%H:%M}' - -# Instant prompt would need a cache file this machine has no reason to carry. -typeset -g POWERLEVEL9K_INSTANT_PROMPT=off -typeset -g POWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD=true diff --git a/.config/zsh/rc.d/05-pre-omz.zsh b/.config/zsh/rc.d/05-pre-omz.zsh index 3943027..2c2d834 100644 --- a/.config/zsh/rc.d/05-pre-omz.zsh +++ b/.config/zsh/rc.d/05-pre-omz.zsh @@ -10,7 +10,11 @@ # 30-path.zsh, so a colour set here is overwritten before the first prompt is # drawn. It belongs in the role files, which run after that. -if [[ -d "${ZSH_CUSTOM:-$ZSH/custom}/themes/powerlevel10k" ]]; then +if [[ "$ROLE" == server ]]; then + # The server draws its own ys-style prompt in 50-server.zsh. A theme loaded + # here would overwrite it before every prompt (p10k does so from precmd). + ZSH_THEME="" +elif [[ -d "${ZSH_CUSTOM:-$ZSH/custom}/themes/powerlevel10k" ]]; then ZSH_THEME="powerlevel10k/powerlevel10k" else # ys is what both machines without powerlevel10k already ran. Without this diff --git a/.config/zsh/rc.d/50-server.zsh b/.config/zsh/rc.d/50-server.zsh index 2dc67f7..92722c5 100644 --- a/.config/zsh/rc.d/50-server.zsh +++ b/.config/zsh/rc.d/50-server.zsh @@ -3,14 +3,9 @@ # The theme and DISABLE_AUTO_UPDATE are in 05-pre-omz.zsh, because oh-my-zsh # reads them while it is being sourced. -# The prompt, in a file of its own because there is more to it than a colour. -# Sourced here rather than earlier: this is the point at which oh-my-zsh has -# loaded powerlevel10k, which is where p10k expects its configuration. -# -# beastix keeps its own ~/.p10k.zsh, sourced from 30-path.zsh. This one is -# separate because a server is reached from whatever terminal is at hand and -# cannot assume the desktop's Nerd Font. -[[ -r "$HOME/.config/zsh/p10k-server.zsh" ]] && source "$HOME/.config/zsh/p10k-server.zsh" +# The prompt: ys layout in gruvbox colours, in a file of its own because +# root's shell uses the same one (installed root-owned, see the file). +[[ -r "$HOME/.config/zsh/server-prompt.zsh" ]] && source "$HOME/.config/zsh/server-prompt.zsh" # German locale. The base does not set one, since the desktop inherits it from # the session and the Mac has its own; an SSH session brings only what the diff --git a/.config/zsh/server-prompt.zsh b/.config/zsh/server-prompt.zsh new file mode 100644 index 0000000..175ed35 --- /dev/null +++ b/.config/zsh/server-prompt.zsh @@ -0,0 +1,31 @@ +# Prompt for the server role: oh-my-zsh's ys layout in gruvbox colours. +# +# Replaces powerlevel10k on shron. Two lines, plain ASCII, readable from any +# terminal. Fixed 256-colour indices approximating gruvbox, because terminal +# themes remap the 16 named colours freely - under gruvbox "white" on "blue" +# was barely legible. +# +# user@host is what has to stand out: plain red for templis, a red block for +# root. The same file is installed root-owned for root's shell (never sourced +# from this home directory, which would let templis run code as root). +# +# Needs oh-my-zsh loaded first (git_prompt_info) and no other theme active. + +# gruvbox (256-colour): red 167, yellow 214, green 142, aqua 108, blue 109, +# grey 245, dark background 235 +ZSH_THEME_GIT_PROMPT_PREFIX=" %F{245}on%f git:%F{108}" +ZSH_THEME_GIT_PROMPT_SUFFIX="%f" +ZSH_THEME_GIT_PROMPT_DIRTY=" %F{167}x" +ZSH_THEME_GIT_PROMPT_CLEAN=" %F{142}o" + +setopt PROMPT_SUBST + +PROMPT=' +%B%(#,%F{167},%F{109})#%f%b \ +%(#,%K{167}%F{235}%B %n@%m %b%f%k,%B%F{167}%n@%m%f%b) \ +%F{245}in%f \ +%B%F{214}%~%f%b\ +$(git_prompt_info) \ +%F{245}[%*]%f%(?,, C:%F{167}%?%f) +%B%F{167}%#%f%b ' +RPROMPT=''