Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
85 lines (65 sloc) 2.16 KB
# Unpure
# based on Pure by Sindre Sorhus
# https://github.com/sindresorhus/pure
# MIT License
# For my own and others sanity
# git:
# %b => current branch
# %a => current action (rebase/merge)
# prompt:
# %F => color dict
# %f => reset color
# %~ => current path
# %* => time
# %n => username
# %m => shortname host
# %(?..) => prompt conditional - %(condition.true.false)
# fastest possible way to check if repo is dirty
prompt_unpure_git_dirty() {
# check if we're in a git repo
[[ "$(command git rev-parse --is-inside-work-tree 2>/dev/null)" == "true" ]] || return
# check if it's dirty
command test -n "$(git status --porcelain --ignore-submodules -unormal)"
(($? == 0)) && echo -n '*'
n=$(git rev-list origin/$(git rev-parse --abbrev-ref HEAD)...HEAD 2>/dev/null | wc -l)
(($n == 1)) && echo -n " ↑"
(($n > 1)) && echo -n " $n↑"
}
prompt_unpure_preexec() {
# shows the current dir and executed command in the title when a process is active
print -Pn "\e]0;"
echo -nE "$PWD:t: $2"
print -Pn "\a"
}
# string length ignoring ansi escapes
prompt_unpure_string_length() {
echo ${#${(S%%)1//(\%([KF1]|)\{*\}|\%[Bbkf])}}
}
prompt_unpure_precmd() {
# shows the full path in the title
print -Pn '\e]0;%~\a'
# git info
vcs_info
# prompt turns red if the previous command didn't exit with 0
PROMPT="%F{blue}%~%F{242}$vcs_info_msg_0_`prompt_unpure_git_dirty` $prompt_unpure_username%f%(?.%F{magenta}.%F{red})❯%f "
}
prompt_unpure_setup() {
# prevent percentage showing up
# if output doesn't end with a newline
export PROMPT_EOL_MARK=''
prompt_opts=(cr subst percent)
autoload -Uz add-zsh-hook
autoload -Uz vcs_info
add-zsh-hook precmd prompt_unpure_precmd
add-zsh-hook preexec prompt_unpure_preexec
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*' use-simple true
zstyle ':vcs_info:*' check-for-changes false
zstyle ':vcs_info:git*' formats ' %b'
zstyle ':vcs_info:git*' actionformats ' %b|%a'
# show username@host if logged in through SSH
[[ "$SSH_CONNECTION" != '' ]] && prompt_unpure_username='%n@%m '
# show username@host if root, with username in white
[[ $UID -eq 0 ]] && prompt_unpure_username='%F{white}%n%F{242}@%m '
}
prompt_unpure_setup "$@"