dotfiles/zsh/custom/themes/bira-nerd.zsh-theme
Mats Ricardo Nomedal a11473e308 initial dotfiles
2026-04-23 23:48:01 +02:00

131 lines
3.2 KiB
Bash

# bira-nerd: Clean Bira-style 2-line prompt with Nerd icons
# Line 1 (left): user@host, cwd, git, pyenv, venv
# Line 1 (right): (venv) time duration exit code
# Line 2: ╰─$ (root gets #)
# No extra blank lines. No column-width hacks.
setopt prompt_subst
########################################
# Helpers
########################################
# Git: branch + dirty/clean
_bira_nerd_git() {
command git rev-parse --is-inside-work-tree &>/dev/null || return
local branch dirty
branch=$(
command git symbolic-ref --quiet --short HEAD 2>/dev/null ||
command git rev-parse --short HEAD 2>/dev/null
) || return
if ! command git diff --quiet --ignore-submodules --cached 2>/dev/null ||
! command git diff --quiet --ignore-submodules 2>/dev/null; then
dirty="%F{red}%f"
else
dirty="%F{green}%f"
fi
echo "%F{yellow}%f ${branch} ${dirty}"
}
# pyenv: show active version if not "system"
_bira_nerd_pyenv() {
command -v pyenv &>/dev/null || return
local v
v=$(pyenv version-name 2>/dev/null) || return
[[ -n "$v" && "$v" != "system" ]] || return
echo "${v}"
}
########################################
# Timing
########################################
preexec() {
BIRA_NERD_START=$EPOCHREALTIME
}
########################################
# precmd: build first line (no printing)
########################################
precmd() {
local left git_info pyenv_info vp
# Start with top-left glyph
left="╭─"
# conda (if available)
if (( $+functions[conda_prompt_info] )); then
left+="$(conda_prompt_info)"
fi
# user@host with icon (includes trailing space)
local user_host="%B%(!.%F{red}.%F{green}) %n@%m%f%b "
# cwd with folder icon (no trailing space)
local current_dir="%B%F{blue} %~%f%b"
left+="${user_host}${current_dir}"
# git info
git_info="$(_bira_nerd_git)"
[[ -n "$git_info" ]] && left+=" ${git_info}"
# pyenv info
pyenv_info="$(_bira_nerd_pyenv)"
[[ -n "$pyenv_info" ]] && left+=" %F{magenta}${pyenv_info}%f"
# left-side venv (oh-my-zsh virtualenv plugin, if present)
if (( $+functions[virtualenv_prompt_info] )); then
vp="$(virtualenv_prompt_info)"
[[ -n "$vp" ]] && left+=" ${vp}"
fi
# ---------- RIGHT SIDE SEGMENTS ----------
local -a right_parts
# (venv) from raw $VIRTUAL_ENV on the right
if [[ -n "$VIRTUAL_ENV" ]]; then
right_parts+=( "%F{magenta}(${VIRTUAL_ENV:t})%f" )
fi
# time
right_parts+=( "%F{242}%D{%H:%M:%S}%f" )
# duration of last command
if [[ -n "$BIRA_NERD_START" ]]; then
local diff secs ms
diff=$(( EPOCHREALTIME - BIRA_NERD_START ))
secs=${diff%.*}
ms=${diff#*.}
if (( secs > 0 )); then
right_parts+=( "%F{33}${secs}s%f" )
else
right_parts+=( "%F{33}${ms:0:2}ms%f" )
fi
fi
# exit code (only when non-zero)
right_parts+=( "%(?..%F{red}%?↵%f)" )
# Join right segments with single spaces
local right="${(j: :)right_parts}"
# Final first line: left + ONE space + right
BIRA_NERD_LINE1="${left} ${right}"
# reset timer
BIRA_NERD_START=""
}
########################################
# Two-line prompt
########################################
PROMPT='${BIRA_NERD_LINE1}
╰─%B%(!.#.$)%b '
RPROMPT=''