1
0
Fork 0
mirror of synced 2024-11-23 07:45:34 -05:00

[prompt] syntax refactor

This commit is contained in:
Matt Hamilton 2016-01-07 08:06:52 -05:00
parent b46edd43a8
commit 9f838982fb
4 changed files with 115 additions and 129 deletions

View file

@ -1,15 +1,13 @@
function prompt_liquidprompt_setup() { prompt_liquidprompt_setup() {
autoload -Uz ex-liquidprompt autoload -Uz ex-liquidprompt
ext-liquidprompt ext-liquidprompt
prompt_opts=(cr subst percent) prompt_opts=(cr subst percent)
} }
function prompt_liquidprompt_preview() { prompt_liquidprompt_preview() {
_lp_set_prompt _lp_set_prompt
prompt_preview_theme liquidprompt prompt_preview_theme liquidprompt
} }
prompt_liquidprompt_setup "$@" prompt_liquidprompt_setup "$@"
# vim:filetype=zsh

View file

@ -3,30 +3,30 @@
# https://github.com/shashankmehta/dotfiles/blob/master/thesetup/zsh/.oh-my-zsh/custom/themes/gitster.zsh-theme # https://github.com/shashankmehta/dotfiles/blob/master/thesetup/zsh/.oh-my-zsh/custom/themes/gitster.zsh-theme
# #
function gst_get_status(){ gst_get_status() {
print "%(?:%F{10}➜ :%F{9}➜ %s)" print "%(?:%F{10}➜ :%F{9}➜ %s)"
} }
function gst_get_pwd(){ gst_get_pwd() {
git_root=$PWD git_root=${PWD}
while [[ $git_root != / && ! -e $git_root/.git ]]; do while [[ ${git_root} != / && ! -e ${git_root}/.git ]]; do
git_root=$git_root:h git_root=${git_root:h}
done done
if [[ $git_root = / ]]; then if [[ ${git_root} = / ]]; then
unset git_root unset git_root
prompt_short_dir="$(short_pwd)" prompt_short_dir="$(short_pwd)"
else else
parent=${git_root%\/*} parent=${git_root%\/*}
prompt_short_dir=${"$(short_pwd)"#$parent/} prompt_short_dir=${"$(short_pwd)"#${parent}/}
fi fi
print $prompt_short_dir print ${prompt_short_dir}
} }
function prompt_gitster_precmd(){ prompt_gitster_precmd() {
PROMPT='$(gst_get_status) %F{white}$(gst_get_pwd) $(git_prompt_info)%f ' PROMPT='$(gst_get_status) %F{white}$(gst_get_pwd) $(git_prompt_info)%f '
} }
function prompt_gitster_setup(){ prompt_gitster_setup() {
ZSH_THEME_GIT_PROMPT_PREFIX="%F{cyan}" ZSH_THEME_GIT_PROMPT_PREFIX="%F{cyan}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%f" ZSH_THEME_GIT_PROMPT_SUFFIX="%f"
ZSH_THEME_GIT_PROMPT_DIRTY=" %F{yellow}✗%f" ZSH_THEME_GIT_PROMPT_DIRTY=" %F{yellow}✗%f"

View file

@ -3,15 +3,15 @@
# https://github.com/S1cK94/minimal # https://github.com/S1cK94/minimal
# #
function minimal_user() { minimal_user() {
echo "%(!.$on_color.$off_color)$prompt_char%f" print "%(!.$on_color.$off_color)$prompt_char%f"
} }
function minimal_jobs() { minimal_jobs() {
echo "%(1j.$on_color.$off_color)$prompt_char%f" print "%(1j.$on_color.$off_color)$prompt_char%f"
} }
function minimal_vimode(){ minimal_vimode(){
local ret="" local ret=""
case $KEYMAP in case $KEYMAP in
@ -25,57 +25,47 @@ function minimal_vimode(){
ret+="$prompt_char%f" ret+="$prompt_char%f"
echo "$ret" print "$ret"
} }
function minimal_status() { minimal_status() {
echo "%(0?.$on_color.$err_color)$prompt_char%f" print "%(0?.$on_color.$err_color)$prompt_char%f"
} }
function -prompt_ellipse(){ minimal_path() {
local string=$1
local sep="$rsc..$path_color"
if [[ $MINIMAL_SHORTEN == true ]] && [[ ${#string} -gt 10 ]]; then
echo "${string:0:4}$sep${string: -4}"
else
echo $string
fi
}
function minimal_path() {
local path_color="%F{244}" local path_color="%F{244}"
local rsc="%f" local rsc="%f"
local sep="$rsc/$path_color" local sep="$rsc/$path_color"
echo "$path_color$(sed s_/_${sep}_g <<< $(short_pwd))$rsc" print "$path_color$(sed s_/_${sep}_g <<< $(short_pwd))$rsc"
} }
function git_branch_name() { git_branch_name() {
local branch_name="$(git rev-parse --abbrev-ref HEAD 2> /dev/null)" local branch_name="$(git rev-parse --abbrev-ref HEAD 2> /dev/null)"
[[ -n $branch_name ]] && echo "$branch_name" [[ -n $branch_name ]] && print "$branch_name"
} }
function git_repo_status(){ git_repo_status(){
local rs="$(git status --porcelain -b)" local rs="$(git status --porcelain -b)"
if $(echo "$rs" | grep -v '^##' &> /dev/null); then # is dirty if $(print "$rs" | grep -v '^##' &> /dev/null); then # is dirty
echo "%F{red}" print "%F{red}"
elif $(echo "$rs" | grep '^## .*diverged' &> /dev/null); then # has diverged elif $(print "$rs" | grep '^## .*diverged' &> /dev/null); then # has diverged
echo "%F{red}" print "%F{red}"
elif $(echo "$rs" | grep '^## .*behind' &> /dev/null); then # is behind elif $(print "$rs" | grep '^## .*behind' &> /dev/null); then # is behind
echo "%F{11}" print "%F{11}"
elif $(echo "$rs" | grep '^## .*ahead' &> /dev/null); then # is ahead elif $(print "$rs" | grep '^## .*ahead' &> /dev/null); then # is ahead
echo "%f" print "%f"
else # is clean else # is clean
echo "%F{green}" print "%F{green}"
fi fi
} }
function minimal_git() { minimal_git() {
local bname=$(git_branch_name) local bname=$(git_branch_name)
if [[ -n $bname ]]; then if [[ -n ${bname} ]]; then
local infos="$(git_repo_status)$bname%f" local infos="$(git_repo_status)${bname}%f"
echo " $infos" print " $infos"
fi fi
} }
@ -84,7 +74,7 @@ function zle-line-init zle-line-finish zle-keymap-select {
zle -R zle -R
} }
function prompt_minimal_precmd() { prompt_minimal_precmd() {
zle -N zle-line-init zle -N zle-line-init
zle -N zle-keymap-select zle -N zle-keymap-select
zle -N zle-line-finish zle -N zle-line-finish
@ -93,7 +83,7 @@ function prompt_minimal_precmd() {
RPROMPT='$(minimal_path)$(minimal_git)' RPROMPT='$(minimal_path)$(minimal_git)'
} }
function prompt_minimal_setup() { prompt_minimal_setup() {
prompt_char="" prompt_char=""
on_color="%F{green}" on_color="%F{green}"
off_color="%f" off_color="%f"

View file

@ -9,97 +9,95 @@
export VIRTUAL_ENV_DISABLE_PROMPT=1 export VIRTUAL_ENV_DISABLE_PROMPT=1
function virtualenv_info { virtualenv_info() {
[ $VIRTUAL_ENV ] && print '('${fg[blue]}`basename $VIRTUAL_ENV`%{${reset_color}%}') ' [ ${VIRTUAL_ENV} ] && print '('${fg[blue]}${VIRTUAL_ENV:t}%{${reset_color}%}') '
} }
function steeef_preexec { steeef_preexec() {
case "$(history $HISTCMD)" in case "$(history $HISTCMD)" in
*git*) *git*)PR_GIT_UPDATE=1
PR_GIT_UPDATE=1 ;;
;; *svn*)PR_GIT_UPDATE=1
*svn*) ;;
PR_GIT_UPDATE=1 esac
;;
esac
} }
function steeef_chpwd { steeef_chpwd() {
PR_GIT_UPDATE=1 PR_GIT_UPDATE=1
} }
function prompt_steeef_precmd { prompt_steeef_precmd() {
if [[ -n "$PR_GIT_UPDATE" ]] ; then if [[ -n "$PR_GIT_UPDATE" ]] ; then
# check for untracked files or updated submodules, since vcs_info doesn't # check for untracked files or updated submodules, since vcs_info doesn't
if git ls-files --other --exclude-standard 2> /dev/null | grep -q "."; then if git ls-files --other --exclude-standard 2> /dev/null | grep -q "."; then
PR_GIT_UPDATE=1 PR_GIT_UPDATE=1
FMT_BRANCH="(%{$turquoise%}%b%u%c%{$hotpink%}●${PR_RST})" FMT_BRANCH="(%{$turquoise%}%b%u%c%{$hotpink%}●${PR_RST})"
else else
FMT_BRANCH="(%{$turquoise%}%b%u%c${PR_RST})" FMT_BRANCH="(%{$turquoise%}%b%u%c${PR_RST})"
fi
zstyle ':vcs_info:*:prompt:*' formats "${FMT_BRANCH} "
vcs_info 'prompt'
PR_GIT_UPDATE=
fi fi
zstyle ':vcs_info:*:prompt:*' formats "${FMT_BRANCH} "
PROMPT=' vcs_info 'prompt'
PR_GIT_UPDATE=
fi
PROMPT='
%{$purple%}%n${${reset_color}%} at %{$orange%}%m${${reset_color}%} in %{$limegreen%}%~${${reset_color}%} $vcs_info_msg_0_$(virtualenv_info)%{${reset_color}%} %{$purple%}%n${${reset_color}%} at %{$orange%}%m${${reset_color}%} in %{$limegreen%}%~${${reset_color}%} $vcs_info_msg_0_$(virtualenv_info)%{${reset_color}%}
$ ' $ '
} }
function prompt_steeef_setup { prompt_steeef_setup() {
#use extended color pallete if available #use extended color pallete if available
if [[ ${TERM} == *256* || ${TERM} == *rxvt* ]]; then if [[ ${TERM} == *256* || ${TERM} == *rxvt* ]]; then
turquoise="%F{81}" turquoise="%F{81}"
orange="%F{166}" orange="%F{166}"
purple="%F{135}" purple="%F{135}"
hotpink="%F{161}" hotpink="%F{161}"
limegreen="%F{118}" limegreen="%F{118}"
else else
turquoise="%F{cyan}" turquoise="%F{cyan}"
orange="%F{yellow}" orange="%F{yellow}"
purple="%F{magenta}" purple="%F{magenta}"
hotpink="%F{red}" hotpink="%F{red}"
limegreen="%F{green}" limegreen="%F{green}"
fi fi
# enable VCS systems you use # enable VCS systems you use
zstyle ':vcs_info:*' enable git svn zstyle ':vcs_info:*' enable git svn
# check-for-changes can be really slow. # check-for-changes can be really slow.
# you should disable it, if you work with large repositories # you should disable it, if you work with large repositories
zstyle ':vcs_info:*:prompt:*' check-for-changes true zstyle ':vcs_info:*:prompt:*' check-for-changes true
# set formats # set formats
# %b - branchname # %b - branchname
# %u - unstagedstr (see below) # %u - unstagedstr (see below)
# %c - stagedstr (see below) # %c - stagedstr (see below)
# %a - action (e.g. rebase-i) # %a - action (e.g. rebase-i)
# %R - repository path # %R - repository path
# %S - path in the repository # %S - path in the repository
PR_RST="%f" PR_RST="%f"
FMT_BRANCH="(%{$turquoise%}%b%u%c${PR_RST})" FMT_BRANCH="(%{$turquoise%}%b%u%c${PR_RST})"
FMT_ACTION="(%{$limegreen%}%a${PR_RST})" FMT_ACTION="(%{$limegreen%}%a${PR_RST})"
FMT_UNSTAGED="%{$orange%}●" FMT_UNSTAGED="%{$orange%}●"
FMT_STAGED="%{$limegreen%}●" FMT_STAGED="%{$limegreen%}●"
zstyle ':vcs_info:*:prompt:*' unstagedstr "${FMT_UNSTAGED}" zstyle ':vcs_info:*:prompt:*' unstagedstr "${FMT_UNSTAGED}"
zstyle ':vcs_info:*:prompt:*' stagedstr "${FMT_STAGED}" zstyle ':vcs_info:*:prompt:*' stagedstr "${FMT_STAGED}"
zstyle ':vcs_info:*:prompt:*' actionformats "${FMT_BRANCH}${FMT_ACTION}" zstyle ':vcs_info:*:prompt:*' actionformats "${FMT_BRANCH}${FMT_ACTION}"
zstyle ':vcs_info:*:prompt:*' formats "${FMT_BRANCH}" zstyle ':vcs_info:*:prompt:*' formats "${FMT_BRANCH}"
zstyle ':vcs_info:*:prompt:*' nvcsformats "" zstyle ':vcs_info:*:prompt:*' nvcsformats ""
PR_GIT_UPDATE=1 PR_GIT_UPDATE=1
autoload -Uz add-zsh-hook autoload -Uz add-zsh-hook
autoload -Uz vcs_info autoload -Uz vcs_info
autoload -Uz colors && colors autoload -Uz colors && colors
add-zsh-hook preexec steeef_preexec add-zsh-hook preexec steeef_preexec
add-zsh-hook chpwd steeef_chpwd add-zsh-hook chpwd steeef_chpwd
add-zsh-hook precmd prompt_steeef_precmd add-zsh-hook precmd prompt_steeef_precmd
prompt_opts=(cr subst percent) prompt_opts=(cr subst percent)
} }
prompt_steeef_setup "$@" prompt_steeef_setup "$@"