prezto/modules/prompt/functions/prompt_hapless_setup
2012-08-26 23:33:21 -04:00

98 lines
3 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#
# A theme based on Steve Losh's Extravagant Prompt with vcs_info integration.
#
# Authors:
# Steve Losh <steve@stevelosh.com>
# Bart Trojanowski <bart@jukie.net>
# Brian Carper <brian@carper.ca>
# steeef <steeef@gmail.com>
# Sorin Ionescu <sorin.ionescu@gmail.com>
# haplesshero13 <haplesshero13@gmail.com>
#
# Left prompt is modified version of the Bash prompt by AntiGenX
# <http://hintsforums.macworld.com/showthread.php?t=17068>
#
# Screenshots:
# <http://www.flickr.com/photos/79770035@N03/7867663652/>
#
function prompt_char {
git branch >/dev/null 2>/dev/null && echo 'λ' && return
hg root >/dev/null 2>/dev/null && echo '☿' && return
echo '$'
}
function rvm_info {
if which rvm-prompt &> /dev/null; then
echo "${_prompt_hapless_colors[5]}$(rvm-prompt i v g)%f"
else
if which rbenv &> /dev/null; then
echo "${_prompt_hapless_colors[5]}$(rbenv version | sed -e "s/ (set.*$//")%f"
fi
fi
}
function prompt_hapless_precmd {
# Check for untracked files or updated submodules since vcs_info does not.
if [[ (-n $(git ls-files --others --exclude-standard 2> /dev/null)) || (-n $(hg status -u 2> /dev/null)) ]]; then
branch_format="(${_prompt_hapless_colors[1]}%b%f%u%c${_prompt_hapless_colors[4]}●%f)"
else
branch_format="(${_prompt_hapless_colors[1]}%b%f%u%c)"
fi
zstyle ':vcs_info:*:prompt:*' formats "${branch_format}"
vcs_info 'prompt'
}
function prompt_hapless_setup {
setopt LOCAL_OPTIONS
unsetopt XTRACE KSH_ARRAYS
prompt_opts=(cr percent subst)
# Load required functions.
autoload -Uz add-zsh-hook
autoload -Uz vcs_info
# Add hook for calling vcs_info before each command.
add-zsh-hook precmd prompt_hapless_precmd
_prompt_hapless_colors=(
"%F{cyan}"
"%F{yellow}"
"%F{magenta}"
"%F{red}"
"%F{green}"
)
# Formats:
# %b - branchname
# %u - unstagedstr (see below)
# %c - stagedstr (see below)
# %a - action (e.g. rebase-i)
# %R - repository path
# %S - path in the repository
local branch_format="(${_prompt_hapless_colors[1]}%b%f%u%c)"
local action_format="(${_prompt_hapless_colors[5]}%a%f)"
local unstaged_format="${_prompt_hapless_colors[2]}●%f"
local staged_format="${_prompt_hapless_colors[5]}●%f"
local return_code='%(?..${_prompt_hapless_colors[4]}%? ↵%f)'
# Set vcs_info parameters.
zstyle ':vcs_info:*' enable git hg
zstyle ':vcs_info:*:prompt:*' check-for-changes true
zstyle ':vcs_info:hg*:prompt:*' get-revision true
zstyle ':vcs_info:hg*:prompt:*' hgrevformat ""
zstyle ':vcs_info:*:prompt:*' unstagedstr "${unstaged_format}"
zstyle ':vcs_info:*:prompt:*' stagedstr "${staged_format}"
zstyle ':vcs_info:*:prompt:*' actionformats "${branch_format}${action_format}"
zstyle ':vcs_info:*:prompt:*' formats "${branch_format}"
zstyle ':vcs_info:*:prompt:*' nvcsformats ""
# Define prompts.
PROMPT="${_prompt_hapless_colors[3]}%n%f@${_prompt_hapless_colors[2]}%m%f:${_prompt_hapless_colors[1]}%~%f"'$(prompt_char) '
RPROMPT="${return_code} "'${vcs_info_msg_0_}$(rvm_info)'
}
prompt_hapless_setup "$@"