Skip to content

Instantly share code, notes, and snippets.

@madisonbullard
Last active June 2, 2023 22:15
Show Gist options
  • Save madisonbullard/835328189138928a552700cd592723da to your computer and use it in GitHub Desktop.
Save madisonbullard/835328189138928a552700cd592723da to your computer and use it in GitHub Desktop.
# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"
# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
git
vscode
zsh-syntax-highlighting
)
source $ZSH/oh-my-zsh.sh
alias zshrc="code ~/.zshrc"
# Created by `pipx` on 2023-05-25 18:58:20
export PATH="$PATH:/Users/madisonbullard/.local/bin"
# *** PROMPT FORMATTING ***
# Echoes a username/host string when connected over SSH (empty otherwise)
ssh_info() {
[[ "$SSH_CONNECTION" != '' ]] && echo "%(!.%{$fg[red]%}.%{$fg[yellow]%})%n%{$reset_color%}@%{$fg[green]%}%m%{$reset_color%}:" || echo ""
}
# Echoes information about Git repository status when inside a Git repository
git_info() {
# Exit if not inside a Git repository
! git rev-parse --is-inside-work-tree > /dev/null 2>&1 && return
# Git branch/tag, or name-rev if on detached head
local GIT_LOCATION=${$(git symbolic-ref -q HEAD || git name-rev --name-only --no-undefined --always HEAD)#(refs/heads/|tags/)}
local AHEAD="%{$fg[red]%}⇡ NUM%{$reset_color%}"
local BEHIND="%{$fg[cyan]%}⇣ NUM%{$reset_color%}"
local MERGING="%{$fg[magenta]%}⚡︎%{$reset_color%}"
local UNTRACKED="%{$fg[red]%}●%{$reset_color%}"
local MODIFIED="%{$fg[yellow]%}●%{$reset_color%}"
local STAGED="%{$fg[green]%}●%{$reset_color%}"
local -a DIVERGENCES
local -a FLAGS
local NUM_AHEAD="$(git log --oneline @{u}.. 2> /dev/null | wc -l | tr -d ' ')"
if [ "$NUM_AHEAD" -gt 0 ]; then
DIVERGENCES+=( "${AHEAD//NUM/$NUM_AHEAD}" )
fi
local NUM_BEHIND="$(git log --oneline ..@{u} 2> /dev/null | wc -l | tr -d ' ')"
if [ "$NUM_BEHIND" -gt 0 ]; then
DIVERGENCES+=( "${BEHIND//NUM/$NUM_BEHIND}" )
fi
local GIT_DIR="$(git rev-parse --git-dir 2> /dev/null)"
if [ -n $GIT_DIR ] && test -r $GIT_DIR/MERGE_HEAD; then
FLAGS+=( "$MERGING" )
fi
if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
FLAGS+=( "$UNTRACKED" )
fi
if ! git diff --quiet 2> /dev/null; then
FLAGS+=( "$MODIFIED" )
fi
if ! git diff --cached --quiet 2> /dev/null; then
FLAGS+=( "$STAGED" )
fi
local -a GIT_INFO
GIT_INFO+=( "%{$fg[cyan]%}±" )
[[ ${#DIVERGENCES[@]} -ne 0 ]] && GIT_INFO+=( "${(j::)DIVERGENCES}" )
[[ ${#FLAGS[@]} -ne 0 ]] && GIT_INFO+=( "${(j::)FLAGS}" )
GIT_INFO+=( "%{$fg[cyan]%}$GIT_LOCATION%{$reset_color%}" )
echo "${(j: :)GIT_INFO}"
}
# Use ❯ as the non-root prompt character; # for root
# Change the prompt character color if the last command had a nonzero exit code
PS1="
\$(ssh_info)%{$fg[magenta]%}%~%u \$(git_info)
%(?.%{$fg[blue]%}.%{$fg[red]%})%(!.#.❯)%{$reset_color%} "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment