helm/zsh/functions/prompt_my_setup

81 lines
2.3 KiB
Plaintext
Raw Normal View History

2014-07-29 02:24:29 -07:00
#
# A simple theme based off sorin
#
# Load dependencies.
pmodload 'helper'
2014-07-29 22:04:54 -07:00
# Show the hostname if this is an SSH session
_prompt_my_host=""
if [ ! -z "$SSH_CLIENT" ]; then
2014-09-22 09:06:02 -07:00
_prompt_my_host=" %B%F{blue}| $(hostname | sed -e 's/\.local$//')%f%b"
2014-07-29 22:04:54 -07:00
fi
2014-09-05 13:54:15 -07:00
function _prompt_my_pwd {
2014-09-22 09:06:02 -07:00
local pwd="${PWD/#$HOME/~}"
if [[ "$pwd" == (#m)[/~] ]]; then
__prompt_my_pwd="$MATCH"
unset MATCH
else
__prompt_my_pwd="${${${(@j:/:M)${(@s:/:)pwd}##.#?}:h}%/}/${pwd:t}"
fi
}
# Only run git-info if a) the last command used git/hub or b) the pwd
# has changed.
function _prompt_git_preexec {
[[ $2 =~ (git|hub) ]] && _EXEC_GIT_COMMAND=1
2014-07-29 02:24:29 -07:00
}
2014-09-22 09:06:02 -07:00
function _prompt_git_precmd {
if [ -n "$_EXEC_GIT_COMMAND" ]; then
_prompt_git_chpwd
unset _EXEC_GIT_COMMAND
fi
}
2014-07-29 02:24:29 -07:00
2014-09-22 09:06:02 -07:00
function _prompt_git_chpwd {
setopt LOCAL_OPTIONS
unsetopt XTRACE KSH_ARRAYS
2014-07-29 02:24:29 -07:00
2014-09-22 09:06:02 -07:00
(( $+functions[git-info] )) && git-info
2014-07-29 02:24:29 -07:00
}
function prompt_my_setup {
2014-09-22 09:06:02 -07:00
setopt LOCAL_OPTIONS
unsetopt XTRACE KSH_ARRAYS
prompt_opts=(cr percent subst)
# Load required functions.
autoload -Uz add-zsh-hook
# Add hook for calling git-info before each command.
add-zsh-hook precmd _prompt_git_precmd
add-zsh-hook chpwd _prompt_git_chpwd
add-zsh-hook preexec _prompt_git_preexec
add-zsh-hook precmd _prompt_my_pwd
# Set editor-info parameters.
zstyle ':prezto:module:editor:info:completing' format '%B%F{red}...%f%b'
zstyle ':prezto:module:editor:info:keymap:primary' format ' %B%F{red}$%f%b'
zstyle ':prezto:module:editor:info:keymap:primary:overwrite' format ' %F{red}♺%f'
zstyle ':prezto:module:editor:info:keymap:alternate' format ' %B%F{green}#%f%b'
# Set git-info parameters.
zstyle ':prezto:module:git:info' verbose 'yes'
zstyle ':prezto:module:git:info:branch' format ':%F{green}%b%f'
zstyle ':prezto:module:git:info:dirty' format '%F{red}+%f'
zstyle ':prezto:module:git:info:keys' format 'prompt' '' 'rprompt' '%b%D'
# Define prompts.
PROMPT='%F{cyan}${__prompt_my_pwd}%f${git_info:+${(e)git_info[prompt]}}%(!. %B%F{red}#%f%b.)${editor_info[keymap]} '
RPROMPT='${editor_info[overwrite]}${VIM:+" %B%F{green}V%f%b"}${git_info[rprompt]}${_prompt_my_host}%(?:: %F{red}⏎%f)'
_prompt_git_chpwd
2014-07-29 02:24:29 -07:00
}
prompt_my_setup "$@"