Created
April 10, 2026 21:53
-
-
Save graywolf336/2e83ecb1fa7e9119b7a451956ff0d109 to your computer and use it in GitHub Desktop.
Show the current atomic view in your zsh prompt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # atomic-prompt.plugin.zsh — show the current atomic view in your zsh prompt | |
| # | |
| # Usage: | |
| # Source this file in your .zshrc (or install via a zsh plugin manager): | |
| # | |
| # source /path/to/atomic-prompt.plugin.zsh | |
| # | |
| # The plugin automatically appends the view to your PROMPT (left side), | |
| # just like Oh-My-Zsh's git_prompt_info(). No extra PROMPT wiring needed. | |
| # | |
| # Customization (set these BEFORE sourcing the plugin to override): | |
| # ATOMIC_PROMPT_PREFIX — text before the view name | |
| # ATOMIC_PROMPT_SUFFIX — text after the view name | |
| # ATOMIC_PROMPT_DIRTY — appended when working tree has changes | |
| # ATOMIC_PROMPT_CLEAN — appended when working tree is clean | |
| # ── Defaults (atomic-branded: magenta chrome, green view name) ────────── | |
| : ${ATOMIC_PROMPT_PREFIX:="%{$fg_bold[magenta]%}atomic:(%{$fg[green]%}"} | |
| : ${ATOMIC_PROMPT_SUFFIX:="%{$reset_color%} "} | |
| : ${ATOMIC_PROMPT_DIRTY:="%{$fg_bold[magenta]%}) %{$fg[yellow]%}%1{✗%}"} | |
| : ${ATOMIC_PROMPT_CLEAN:="%{$fg_bold[magenta]%})"} | |
| # ── Core helpers ──────────────────────────────────────────────────────── | |
| # Walk up to find the .atomic directory, similar to how git finds .git. | |
| _atomic_repo_root() { | |
| local dir="$PWD" | |
| while [[ "$dir" != "/" ]]; do | |
| if [[ -f "$dir/.atomic/pristine.redb" ]]; then | |
| echo "$dir" | |
| return 0 | |
| fi | |
| dir="${dir:h}" | |
| done | |
| return 1 | |
| } | |
| # Read the current view name directly from disk (no subprocess). | |
| _atomic_current_view() { | |
| local root | |
| root="$(_atomic_repo_root)" || return 1 | |
| local dot_dir="$root/.atomic" | |
| local view | |
| if [[ -f "$dot_dir/current_view" ]]; then | |
| view="$(<"$dot_dir/current_view")" | |
| elif [[ -f "$dot_dir/current_stack" ]]; then | |
| view="$(<"$dot_dir/current_stack")" | |
| else | |
| view="dev" | |
| fi | |
| echo "${view## }" | |
| } | |
| # ── Prompt functions ──────────────────────────────────────────────────── | |
| # Full-featured: view name + dirty indicator via `atomic status -s`. | |
| atomic_view_prompt_info() { | |
| local view | |
| view="$(_atomic_current_view)" || return | |
| local dirty_clean="$ATOMIC_PROMPT_CLEAN" | |
| if command -v atomic &>/dev/null; then | |
| local status_output | |
| status_output="$(atomic status -s 2>/dev/null)" | |
| if [[ -n "$status_output" ]]; then | |
| dirty_clean="$ATOMIC_PROMPT_DIRTY" | |
| fi | |
| fi | |
| echo "${ATOMIC_PROMPT_PREFIX}${view}${dirty_clean}${ATOMIC_PROMPT_SUFFIX}" | |
| } | |
| # Lightweight: view name only, zero subprocess overhead. | |
| atomic_view_prompt_info_fast() { | |
| local view | |
| view="$(_atomic_current_view)" || return | |
| echo "${ATOMIC_PROMPT_PREFIX}${view}${ATOMIC_PROMPT_CLEAN}${ATOMIC_PROMPT_SUFFIX}" | |
| } | |
| # ── Auto-attach to PROMPT ─────────────────────────────────────────────── | |
| # Guard against double-attach when re-sourcing .zshrc. | |
| if [[ "$PROMPT" != *'atomic_view_prompt_info'* ]]; then | |
| PROMPT+='$(atomic_view_prompt_info)' | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment