2015-12-10 14:45:06 -05:00
|
|
|
function prompt_pwd {
|
2015-08-01 19:23:27 -04:00
|
|
|
local pwd="${PWD/#$HOME/~}"
|
|
|
|
|
|
|
|
if [[ "$pwd" == (#m)[/~] ]]; then
|
2015-12-10 14:45:06 -05:00
|
|
|
_prompt_pwd="$MATCH"
|
2015-08-01 19:23:27 -04:00
|
|
|
unset MATCH
|
|
|
|
else
|
2015-12-10 14:45:06 -05:00
|
|
|
_prompt_pwd="${${${(@j:/:M)${(@s:/:)pwd}##.#?}:h}%/}/${pwd:t}"
|
2015-08-01 19:23:27 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-12-10 14:45:06 -05:00
|
|
|
function prompt_userhost {
|
2015-12-10 15:46:53 -05:00
|
|
|
eval PR_USER="%F{green}%n%f"
|
2015-08-01 19:23:27 -04:00
|
|
|
if [[ -n "$SSH_CLIENT" || -n "$SSH2_CLIENT" ]]; then
|
|
|
|
eval PR_HOST='%F{yellow}%M%f' #SSH
|
|
|
|
else
|
|
|
|
eval PR_HOST='%F{green}%M%f' # no SSH
|
|
|
|
fi
|
|
|
|
|
2015-12-10 14:45:06 -05:00
|
|
|
_prompt_userhost="${PR_USER}%F{cyan}@${PR_HOST}%f"
|
2015-08-01 19:23:27 -04:00
|
|
|
}
|
|
|
|
|
2015-12-10 14:45:06 -05:00
|
|
|
function prompt_ruby {
|
2015-08-01 19:23:27 -04:00
|
|
|
if which rvm-prompt &> /dev/null; then
|
2015-12-10 14:45:06 -05:00
|
|
|
_prompt_ruby="[%F{red}$(rvm-prompt i v g s)%f]"
|
2015-08-01 19:23:27 -04:00
|
|
|
else
|
|
|
|
if which rbenv &> /dev/null; then
|
2015-12-10 14:45:06 -05:00
|
|
|
_prompt_ruby="[%F{red}$(rbenv version | sed -e "s/ (set.*$//")%f]"
|
2015-08-01 19:23:27 -04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-12-10 14:45:06 -05:00
|
|
|
function prompt_vcs {
|
2015-08-01 19:23:27 -04:00
|
|
|
local branch_format="(%F{yellow}%b%f%u%c)"
|
|
|
|
local action_format="(%F{yellow}%a%f)"
|
|
|
|
local unstaged_format="%F{green}*%f"
|
|
|
|
local staged_format="%F{yellow}*%f"
|
|
|
|
|
2015-12-10 15:46:53 -05:00
|
|
|
zstyle ':vcs_info:*' enable git hg svn
|
2015-08-01 19:23:27 -04:00
|
|
|
zstyle ':vcs_info:*:prompt:*' check-for-changes true
|
|
|
|
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 ""
|
|
|
|
|
2015-12-10 14:45:06 -05:00
|
|
|
_prompt_vcs="${vcs_info_msg_0_}"
|
2015-08-01 19:23:27 -04:00
|
|
|
}
|
|
|
|
|
2015-12-10 14:45:06 -05:00
|
|
|
function prompt_precmd {
|
2015-08-01 19:23:27 -04:00
|
|
|
setopt LOCAL_OPTIONS
|
|
|
|
unsetopt XTRACE KSH_ARRAYS
|
|
|
|
|
|
|
|
# Format PWD.
|
2015-12-10 14:45:06 -05:00
|
|
|
prompt_pwd
|
2015-08-01 19:23:27 -04:00
|
|
|
|
|
|
|
# vcs prompt
|
|
|
|
if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
|
2015-08-03 14:27:17 -04:00
|
|
|
branch_format="[%F{yellow}%b%f%u%c%F{yellow}*%f]"
|
2015-08-01 19:23:27 -04:00
|
|
|
else
|
2015-08-03 14:27:17 -04:00
|
|
|
branch_format="[%F{yellow}%b%f%u%c]"
|
2015-08-01 19:23:27 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
zstyle ':vcs_info:*:prompt:*' formats "${branch_format}"
|
|
|
|
|
|
|
|
vcs_info 'prompt'
|
|
|
|
}
|
|
|
|
|
2015-12-10 14:45:06 -05:00
|
|
|
function prompt_setup {
|
2015-08-01 19:23:27 -04:00
|
|
|
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 git-info before each command.
|
2015-12-10 14:45:06 -05:00
|
|
|
add-zsh-hook precmd prompt_precmd
|
2015-08-01 19:23:27 -04:00
|
|
|
|
|
|
|
# keep this
|
|
|
|
SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? '
|
|
|
|
|
|
|
|
# custom stuff
|
2015-12-10 14:45:06 -05:00
|
|
|
prompt_ruby
|
|
|
|
prompt_userhost
|
|
|
|
prompt_vcs
|
2015-08-01 19:23:27 -04:00
|
|
|
|
|
|
|
local current_time="[%B%D{%I:%M:%S}%b]"
|
|
|
|
local current_dir='%B%F{blue}%~%f%b'
|
|
|
|
local return_code="%(?..%?)"
|
2015-12-10 14:45:06 -05:00
|
|
|
local user_host=$_prompt_userhost
|
|
|
|
local ruby_info=$_prompt_ruby
|
|
|
|
local git_info=$_prompt_vcs
|
2015-12-10 15:46:53 -05:00
|
|
|
|
2015-08-01 19:23:27 -04:00
|
|
|
local PR_PROMPT="%(?.%F{green}->.%F{red}-%B${return_code}%b%F{red}->%{%})%f"
|
|
|
|
|
|
|
|
PROMPT="${current_time} ${user_host} ${current_dir} ${ruby_info} ${git_info}
|
|
|
|
|$PR_PROMPT "
|
|
|
|
}
|
|
|
|
|
2015-12-10 14:45:06 -05:00
|
|
|
prompt_setup "$@"
|