Last active
May 7, 2026 12:42
-
-
Save TravisBernard/98669fcefbca224cabafd72c4fba4483 to your computer and use it in GitHub Desktop.
Git Prompt for ZSH
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
| #### | |
| # Some of my favorite things | |
| #### | |
| alias g="git" | |
| alias bethel="code ~/Development/Bethel" | |
| alias og="claude --model=\"claude-opus-4-6[1m]\" --effort=high" | |
| alias azlogin="az login --allow-no-subscriptions --tenant e9b2b7ba-b238-42a9-b271-2adfc82da650" | |
| #### | |
| # GIT PROMPT | |
| # adapted from: https://www.themoderncoder.com/add-git-branch-information-to-your-zsh-prompt/ | |
| # with additions from: https://salferrarello.com/zsh-git-status-prompt/ | |
| #### | |
| # Load version control information | |
| autoload -Uz vcs_info | |
| precmd() { vcs_info } | |
| # Format the vcs_info_msg_0_ variable | |
| # Will turn red if there are unstaged files and yellow if there are modified files - like git status | |
| # Will trim branch names to 15 characters (%15.15b) | |
| zstyle ':vcs_info:*' check-for-changes true | |
| zstyle ':vcs_info:*' unstagedstr '%F{red}' | |
| zstyle ':vcs_info:*' stagedstr '%F{yellow}' | |
| zstyle ':vcs_info:git:*' formats '| %F{green}%c%u%15.15b%f ' | |
| zstyle ':vcs_info:git:*' actionformats '| %F{red}%15.15b|%a%f ' | |
| #### | |
| # NODE VERSION PROMPT | |
| # Only updates on directory change (chpwd) to keep the prompt fast | |
| #### | |
| _node_prompt_info='' | |
| _update_node_prompt() { | |
| local current="$(node --version)" | |
| local color="green" | |
| local dir="$PWD" | |
| while [[ "$dir" != "/" ]]; do | |
| if [[ -f "$dir/.nvmrc" ]]; then | |
| local expected="$(<"$dir/.nvmrc")" | |
| expected="${expected#v}" | |
| local current_stripped="${current#v}" | |
| if [[ "$current_stripped" != "$expected" && "$current_stripped" != "$expected".* ]]; then | |
| color="red" | |
| fi | |
| break | |
| fi | |
| dir="${dir:h}" | |
| done | |
| _node_prompt_info="%F{$color}⬢ ${current}%f " | |
| } | |
| _update_node_prompt | |
| chpwd_functions+=(_update_node_prompt) | |
| _short_pwd() { | |
| local p="${PWD/#$HOME/~}" | |
| local parts=("${(@s:/:)p}") | |
| local total=${#parts} | |
| if (( total > 3 )); then | |
| local skipped=$(( total - 2 )) | |
| echo "[${skipped}]/${parts[-2]}/${parts[-1]}" | |
| else | |
| echo "$p" | |
| fi | |
| } | |
| # Set up the prompt (with git branch and node version) | |
| setopt PROMPT_SUBST | |
| PROMPT='${_node_prompt_info}${vcs_info_msg_0_}| $(_short_pwd) %# ' | |
| #### | |
| # Set up context aware history similar to oh-my-zsh | |
| # see https://unix.stackexchange.com/questions/97843/how-can-i-search-history-with-text-already-entered-at-the-prompt-in-zsh | |
| #### | |
| autoload -U history-search-end | |
| zle -N history-beginning-search-backward-end history-search-end | |
| zle -N history-beginning-search-forward-end history-search-end | |
| bindkey $terminfo[kcuu1] history-beginning-search-backward-end | |
| bindkey $terminfo[kcud1] history-beginning-search-forward-end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment