From 108ceb9267047c51e0fde700f7a10cd9355b8501 Mon Sep 17 00:00:00 2001 From: Andrew Lorimer Date: Thu, 25 Sep 2025 23:00:38 +1000 Subject: [PATCH] [zsh] fix prompt for SSH sessions --- zsh/.oh-my-zsh/custom/themes/custom.zsh-theme | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 zsh/.oh-my-zsh/custom/themes/custom.zsh-theme diff --git a/zsh/.oh-my-zsh/custom/themes/custom.zsh-theme b/zsh/.oh-my-zsh/custom/themes/custom.zsh-theme new file mode 100644 index 0000000..16ce024 --- /dev/null +++ b/zsh/.oh-my-zsh/custom/themes/custom.zsh-theme @@ -0,0 +1,75 @@ +# zsh theme by Andrew Lorimer + +# Prompt: +# %F => Color codes +# %f => Reset color +# %~ => Current path +# %(x.true.false) => Specifies a ternary expression +# ! => True if the shell is running with root privileges +# ? => True if the exit status of the last command was success +# +# Git: +# %a => Current action (rebase/merge) +# %b => Current branch (hide if master) +# %c => Staged changes +# %u => Unstaged changes +# +# Terminal: +# \n => Newline/Line Feed (LF) + +setopt PROMPT_SUBST + +autoload -U add-zsh-hook +autoload -Uz vcs_info + +# Use 256 colours if available +if [[ "${terminfo[colors]}" -ge 256 ]]; then + color0="%F{107}" # blue context/angle bracket + color1="%F{256}" # white pwd text + color2="%F{245}" # grey git branch text + color3="%F{167}" # red error/untracked + color4="%F{209}" # orange warning/unstaged/suspended + color5="%F{107}" # green success/staged +else # Fall back to standard ANSI names + color0="%F{blue}" + color1="%F{white}" + color2="%F{cyan}" + color3="%F{red}" + color4="%F{yellow}" + color5="%F{green}" +fi +reset="%{%f%}" + +FMT_VCS_STATUS="%{$color2%}%b%u%c%{%f%} " + +zstyle ':vcs_info:*' enable git +zstyle ':vcs_info:*' check-for-changes true +zstyle ':vcs_info:*' unstagedstr "%{%f%} %{$color4%}●" +zstyle ':vcs_info:*' stagedstr "%{%f%} %{$color5%}✚" +zstyle ':vcs_info:*' actionformats "(%{$color5%}%a%{%f%})${FMT_VCS_STATUS}" +zstyle ':vcs_info:*' formats "${FMT_VCS_STATUS}" +zstyle ':vcs_info:*' nvcsformats "" # return nothing when no VCS in pwd +zstyle ':vcs_info:git*+set-message:*' hooks git-untracked + +# Check for untracked files ++vi-git-untracked() { + if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' ]] && \ + git status --porcelain | grep --max-count=1 '^??' &> /dev/null; then + hook_com[staged]+="%{%f%} %{$color3%}●" + fi +} + +add-zsh-hook precmd vcs_info + +# Context (user@host) +if [[ "$SSH_CLIENT" ]]; then + #context="%{$color0%}%n@%m " + context='%{$color0%}%n@%m%f ' +fi + +# Check for suspended processes +checkjobs() { + [[ $(jobs -l | wc -l) -gt 0 ]] && echo "%{$color4%}● " +} + +PROMPT='%1(j.'$color4'● .)'$context'%~ ${vcs_info_msg_0_//master/} %(?.'$color0'.'$color3')%(!.#.❯)%f ' -- 2.49.0