Skip to content

Instantly share code, notes, and snippets.

@benmezger
Created September 4, 2016 19:26
Show Gist options
  • Save benmezger/25a786a133d6d7143aefdb5ef6b8662b to your computer and use it in GitHub Desktop.
Save benmezger/25a786a133d6d7143aefdb5ef6b8662b to your computer and use it in GitHub Desktop.
My Custom zprezto prompt theme
############ BEGIN SORIN #############
# https://github.com/sorin-ionescu/prezto/blob/master/modules/prompt/functions/prompt_sorin_setup
function prompt_unix_pwd {
local pwd="${PWD/#$HOME/~}"
if [[ "$pwd" == (#m)[/~] ]]; then
_prompt_unix_pwd="$MATCH"
unset MATCH
else
_prompt_unix_pwd="${${${${(@j:/:M)${(@s:/:)pwd}##.#?}:h}%/}//\%/%%}/${${pwd:t}//\%/%%}"
fi
}
function prompt_unix_git_info {
if (( _prompt_unix_precmd_async_pid > 0 )); then
# Append Git status.
if [[ -s "$_prompt_unix_precmd_async_data" ]]; then
alias typeset='typeset -g'
source "$_prompt_unix_precmd_async_data"
RPROMPT+='${git_info:+${(e)git_info[status]}}'
unalias typeset
fi
# Reset PID.
_prompt_unix_precmd_async_pid=0
# Redisplay prompt.
zle && zle reset-prompt
fi
}
function prompt_unix_precmd_async {
# Get Git repository information.
if (( $+functions[git-info] )); then
git-info
typeset -p git_info >! "$_prompt_unix_precmd_async_data"
fi
# Signal completion to parent process.
kill -WINCH $$
}
function prompt_unix_precmd {
setopt LOCAL_OPTIONS
unsetopt XTRACE KSH_ARRAYS
# format PWD
prompt_unix_pwd
# Kill the old process of slow commands if it is still running.
if (( _prompt_unix_precmd_async_pid > 0 )); then
kill -KILL "$_prompt_unix_precmd_async_pid" &>/dev/null
fi
# Compute slow commands in the background.
trap prompt_unix_git_info WINCH
prompt_unix_precmd_async &!
_prompt_unix_precmd_async_pid=$!
}
############ END SORIN SETUP ##############
function prompt_unix_setup {
setopt LOCAL_OPTIONS
unsetopt XTRACE KSH_ARRAYS
prompt_opts=(cr percent subst)
_prompt_unix_precmd_async_pid=0
_prompt_unix_precmd_async_data="${TMPPREFIX}-prompt_unix_data"
# Load required functions.
autoload -Uz add-zsh-hook
# Add a hook for calling info functions before each command.
add-zsh-hook precmd prompt_unix_precmd
_prompt_unix_colors=(
"%F{1}"
)
# Set git-info parameters.
zstyle ':prezto:module:git:info' verbose 'no'
zstyle ':prezto:module:git:info:action' format ' +%s'
zstyle ':prezto:module:git:info:branch' format ' %F{8}%b%f'
zstyle ':prezto:module:git:info:commit' format ' %F{white}%.7c%f'
zstyle ':prezto:module:git:info:indexed' format ' '
zstyle ':prezto:module:git:info:unindexed' format ' '
zstyle ':prezto:module:git:info:untracked' format ' '
zstyle ':prezto:module:git:info:dirty' format ' %F{8}✗%f'
zstyle ':prezto:module:git:info:keys' format 'rprompt' '%b%c%s%D'
# Define prompts.
PROMPT='%n λ %F{1}%m %F{4}${_prompt_unix_pwd} %f$ '
RPROMPT='${git_info[rprompt]}'
}
prompt_unix_setup "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment