Skip to content

Instantly share code, notes, and snippets.

@BlairLeduc
Created September 6, 2022 15:06
Show Gist options
  • Save BlairLeduc/f0c7b662a9f5306ab5ac9b9bf97c16c5 to your computer and use it in GitHub Desktop.
Save BlairLeduc/f0c7b662a9f5306ab5ac9b9bf97c16c5 to your computer and use it in GitHub Desktop.
My zsh theme I use in WSL, based on the apple theme
## Options
THEME_PROMPT_PREFIX=${THEME_PROMPT_PREFIX:-''}
THEME_VI_INS_MODE_SYMBOL=${THEME_VI_INS_MODE_SYMBOL:-'❖'}
THEME_VI_CMD_MODE_SYMBOL=${THEME_VI_CMD_MODE_SYMBOL:-'ᐅ'}
## Set symbol for the initial mode
THEME_VI_MODE_SYMBOL="${THEME_VI_INS_MODE_SYMBOL}"
autoload -Uz vcs_info
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' unstagedstr '%F{red}*' # display this when there are unstaged changes
zstyle ':vcs_info:*' stagedstr '%F{yellow}+' # display this when there are staged changes
zstyle ':vcs_info:*' actionformats '%F{5}[%F{2}%b%F{3}|%F{1}%a%c%u%F{5}]%f '
zstyle ':vcs_info:*' formats '%F{5}[%F{2}%b%c%u%F{5}]%f '
zstyle ':vcs_info:svn:*' branchformat '%b'
zstyle ':vcs_info:svn:*' actionformats '%F{5}[%F{2}%b%F{1}:%F{3}%i%F{3}|%F{1}%a%c%u%F{5}]%f '
zstyle ':vcs_info:svn:*' formats '%F{5}[%F{2}%b%F{1}:%F{3}%i%c%u%F{5}]%f '
zstyle ':vcs_info:*' enable git cvs svn
# on keymap change, define the mode and redraw prompt
zle-keymap-select() {
if [ "${KEYMAP}" = 'vicmd' ]; then
THEME_VI_MODE_SYMBOL="${THEME_VI_CMD_MODE_SYMBOL}"
else
THEME_VI_MODE_SYMBOL="${THEME_VI_INS_MODE_SYMBOL}"
fi
zle reset-prompt
}
zle -N zle-keymap-select
# reset to default mode at the end of line input reading
zle-line-finish() {
THEME_VI_MODE_SYMBOL="${THEME_VI_INS_MODE_SYMBOL}"
}
zle -N zle-line-finish
# Fix a bug when you C-c in CMD mode, you'd be prompted with CMD mode indicator
# while in fact you would be in INS mode.
# Fixed by catching SIGINT (C-c), set mode to INS and repropagate the SIGINT,
# so if anything else depends on it, we will not break it.
TRAPINT() {
THEME_VI_MODE_SYMBOL="${THEME_VI_INS_MODE_SYMBOL}"
return $(( 128 + $1 ))
}
function toon {
echo -n $THEME_VI_MODE_SYMBOL
}
theme_precmd () {
vcs_info
}
setopt prompt_subst
PROMPT='%{$fg[cyan]%}$(toon)%{$reset_color%} %~/ %{$reset_color%}${vcs_info_msg_0_}%{$reset_color%}'
autoload -U add-zsh-hook
add-zsh-hook precmd theme_precmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment