Created
June 25, 2025 18:02
-
-
Save birkholz/ff0d1e1873af82be08212c4e619ff793 to your computer and use it in GitHub Desktop.
My custom ZSH theme that emulates my Fish 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
| # ZSH Theme emulating the Fish shell's default prompt. | |
| _fishy_collapsed_wd() { | |
| local i pwd | |
| pwd=("${(s:/:)PWD/#$HOME/~}") | |
| if (( $#pwd > 1 )); then | |
| for i in {1..$(($#pwd-1))}; do | |
| if [[ "$pwd[$i]" = .* ]]; then | |
| pwd[$i]="${${pwd[$i]}[1,2]}" | |
| else | |
| pwd[$i]="${${pwd[$i]}[1]}" | |
| fi | |
| done | |
| fi | |
| echo -n "${(j:/:)pwd}" | |
| } | |
| _in_go_project() { | |
| local dir="$PWD" | |
| while [[ "$dir" != "/" ]]; do | |
| if [[ -f "$dir/go.mod" ]] || [[ -f "$dir/.go-version" ]]; then | |
| return 0 | |
| fi | |
| dir="$(dirname "$dir")" | |
| done | |
| return 1 | |
| } | |
| _update_prompt_vars() { | |
| ctime="$(date +"%H:%M")" | |
| collapsed_wd="$(_fishy_collapsed_wd)" | |
| pyenv=$(basename "$PYENV_VERSION") | |
| # Only get goenv version if we're in a Go project | |
| if _in_go_project; then | |
| goenv=$(goenv version-name 2>/dev/null) | |
| else | |
| goenv="" | |
| fi | |
| [[ -n "$pyenv" ]] && export pyenv="λ(${pyenv})" | |
| [[ -n "$goenv" ]] && export goenv="∆(${goenv})" | |
| } | |
| precmd_functions+=(_update_prompt_vars) | |
| local user_color='green'; [ $UID -eq 0 ] && user_color='red' | |
| local host_color='white'; [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ] && host_color='yellow' | |
| PROMPT='→ ' | |
| local return_status="%{$fg_bold[red]%}%(?.. %?)%{$reset_color%}" | |
| RPROMPT='%{$fg[cyan]%}${collapsed_wd}%{$reset_color%}$(git_prompt_info)$(git_prompt_status)%{$reset_color%}${pyenv}${goenv}${return_status} ⎨${ctime}' | |
| setopt PROMPT_SUBST | |
| ZSH_THEME_GIT_PROMPT_PREFIX="⋅" | |
| ZSH_THEME_GIT_PROMPT_SUFFIX="" | |
| ZSH_THEME_GIT_PROMPT_DIRTY="" | |
| ZSH_THEME_GIT_PROMPT_CLEAN="" | |
| ZSH_THEME_GIT_PROMPT_ADDED="⋅%{$fg_bold[green]%}+" | |
| ZSH_THEME_GIT_PROMPT_MODIFIED="⋅%{$fg_bold[blue]%}!" | |
| ZSH_THEME_GIT_PROMPT_DELETED="⋅%{$fg_bold[red]%}-" | |
| ZSH_THEME_GIT_PROMPT_RENAMED="⋅%{$fg_bold[magenta]%}>" | |
| ZSH_THEME_GIT_PROMPT_UNMERGED="⋅%{$fg_bold[yellow]%}#" | |
| ZSH_THEME_GIT_PROMPT_UNTRACKED="⋅%{$fg_bold[cyan]%}?" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment