Skip to content

Instantly share code, notes, and snippets.

@cworld1
Last active July 28, 2023 14:38
Show Gist options
  • Save cworld1/caeb301cc71f96eaf18b1eed982cdd7b to your computer and use it in GitHub Desktop.
Save cworld1/caeb301cc71f96eaf18b1eed982cdd7b to your computer and use it in GitHub Desktop.
A shell theme for [zim framework](https://github.com/zimfw/zimfw) on Z-shell (zsh). If you are a Windows user (use Cygwin/msys2), please uncomment line 4 to fix path problem. NOTE: `duration-info`, `git-info` module is required in zim.
_prompt_basher_pwd() {
local git_root current_dir
if git_root=$(command git rev-parse --show-toplevel 2>/dev/null); then
# git_root=$(cygpath -u "$git_root") # 将 Windows 风格的路径转换为 Unix 风格的路径
current_dir="${PWD#${git_root:h}/}"
else
current_dir=${(%):-%3~}
fi
print -n "%F{blue}󰉖 ${current_dir}%b"
}
VIRTUAL_ENV_DISABLE_PROMPT=1
setopt nopromptbang prompt{cr,percent,sp,subst}
# Depends on duration-info module to show last command duration
# https://github.com/zimfw/duration-info
if (( ${+functions[duration-info-preexec]} && \
${+functions[duration-info-precmd]} )); then
zstyle ':zim:duration-info' threshold 0.3
zstyle ':zim:duration-info' format ' took %B%F{yellow}%d%f%b'
add-zsh-hook preexec duration-info-preexec
add-zsh-hook precmd duration-info-precmd
fi
# Requires the `git-info` zmodule to be included in the .zimrc file.
typeset -gA git_info
if (( ${+functions[git-info]} )); then
zstyle ':zim:git-info:branch' format '%b'
zstyle ':zim:git-info:commit' format '%c'
zstyle ':zim:git-info:clean' format ''
zstyle ':zim:git-info:dirty' format '*'
zstyle ':zim:git-info:keys' format \
'prompt' ' %F{cyan}󰊢 %b%c%C%D'
autoload -Uz add-zsh-hook && add-zsh-hook precmd git-info
fi
# Left
PS1='${VIRTUAL_ENV:+"(${VIRTUAL_ENV:t}) "}%(?:%F{magenta}:%F{red})󰙃 %n%f $(_prompt_basher_pwd)${(e)git_info[prompt]} %f%(!:#:$) '
# Right
RPS1='%(?::%F{red}$?%f)${duration_info}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment