[prompt] syntax refactor
This commit is contained in:
parent
b46edd43a8
commit
9f838982fb
4 changed files with 115 additions and 129 deletions
|
@ -1,15 +1,13 @@
|
|||
function prompt_liquidprompt_setup() {
|
||||
autoload -Uz ex-liquidprompt
|
||||
prompt_liquidprompt_setup() {
|
||||
autoload -Uz ex-liquidprompt
|
||||
|
||||
ext-liquidprompt
|
||||
prompt_opts=(cr subst percent)
|
||||
ext-liquidprompt
|
||||
prompt_opts=(cr subst percent)
|
||||
}
|
||||
|
||||
function prompt_liquidprompt_preview() {
|
||||
_lp_set_prompt
|
||||
prompt_preview_theme liquidprompt
|
||||
prompt_liquidprompt_preview() {
|
||||
_lp_set_prompt
|
||||
prompt_preview_theme liquidprompt
|
||||
}
|
||||
|
||||
prompt_liquidprompt_setup "$@"
|
||||
|
||||
# vim:filetype=zsh
|
||||
|
|
|
@ -3,30 +3,30 @@
|
|||
# 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)"
|
||||
}
|
||||
|
||||
function gst_get_pwd(){
|
||||
git_root=$PWD
|
||||
while [[ $git_root != / && ! -e $git_root/.git ]]; do
|
||||
git_root=$git_root:h
|
||||
gst_get_pwd() {
|
||||
git_root=${PWD}
|
||||
while [[ ${git_root} != / && ! -e ${git_root}/.git ]]; do
|
||||
git_root=${git_root:h}
|
||||
done
|
||||
if [[ $git_root = / ]]; then
|
||||
if [[ ${git_root} = / ]]; then
|
||||
unset git_root
|
||||
prompt_short_dir="$(short_pwd)"
|
||||
else
|
||||
parent=${git_root%\/*}
|
||||
prompt_short_dir=${"$(short_pwd)"#$parent/}
|
||||
prompt_short_dir=${"$(short_pwd)"#${parent}/}
|
||||
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 '
|
||||
}
|
||||
|
||||
function prompt_gitster_setup(){
|
||||
prompt_gitster_setup() {
|
||||
ZSH_THEME_GIT_PROMPT_PREFIX="%F{cyan}"
|
||||
ZSH_THEME_GIT_PROMPT_SUFFIX="%f"
|
||||
ZSH_THEME_GIT_PROMPT_DIRTY=" %F{yellow}✗%f"
|
||||
|
|
|
@ -3,15 +3,15 @@
|
|||
# https://github.com/S1cK94/minimal
|
||||
#
|
||||
|
||||
function minimal_user() {
|
||||
echo "%(!.$on_color.$off_color)$prompt_char%f"
|
||||
minimal_user() {
|
||||
print "%(!.$on_color.$off_color)$prompt_char%f"
|
||||
}
|
||||
|
||||
function minimal_jobs() {
|
||||
echo "%(1j.$on_color.$off_color)$prompt_char%f"
|
||||
minimal_jobs() {
|
||||
print "%(1j.$on_color.$off_color)$prompt_char%f"
|
||||
}
|
||||
|
||||
function minimal_vimode(){
|
||||
minimal_vimode(){
|
||||
local ret=""
|
||||
|
||||
case $KEYMAP in
|
||||
|
@ -25,57 +25,47 @@ function minimal_vimode(){
|
|||
|
||||
ret+="$prompt_char%f"
|
||||
|
||||
echo "$ret"
|
||||
print "$ret"
|
||||
}
|
||||
|
||||
function minimal_status() {
|
||||
echo "%(0?.$on_color.$err_color)$prompt_char%f"
|
||||
minimal_status() {
|
||||
print "%(0?.$on_color.$err_color)$prompt_char%f"
|
||||
}
|
||||
|
||||
function -prompt_ellipse(){
|
||||
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() {
|
||||
minimal_path() {
|
||||
local path_color="%F{244}"
|
||||
local rsc="%f"
|
||||
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)"
|
||||
[[ -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)"
|
||||
|
||||
if $(echo "$rs" | grep -v '^##' &> /dev/null); then # is dirty
|
||||
echo "%F{red}"
|
||||
elif $(echo "$rs" | grep '^## .*diverged' &> /dev/null); then # has diverged
|
||||
echo "%F{red}"
|
||||
elif $(echo "$rs" | grep '^## .*behind' &> /dev/null); then # is behind
|
||||
echo "%F{11}"
|
||||
elif $(echo "$rs" | grep '^## .*ahead' &> /dev/null); then # is ahead
|
||||
echo "%f"
|
||||
if $(print "$rs" | grep -v '^##' &> /dev/null); then # is dirty
|
||||
print "%F{red}"
|
||||
elif $(print "$rs" | grep '^## .*diverged' &> /dev/null); then # has diverged
|
||||
print "%F{red}"
|
||||
elif $(print "$rs" | grep '^## .*behind' &> /dev/null); then # is behind
|
||||
print "%F{11}"
|
||||
elif $(print "$rs" | grep '^## .*ahead' &> /dev/null); then # is ahead
|
||||
print "%f"
|
||||
else # is clean
|
||||
echo "%F{green}"
|
||||
print "%F{green}"
|
||||
fi
|
||||
}
|
||||
|
||||
function minimal_git() {
|
||||
minimal_git() {
|
||||
local bname=$(git_branch_name)
|
||||
if [[ -n $bname ]]; then
|
||||
local infos="$(git_repo_status)$bname%f"
|
||||
echo " $infos"
|
||||
if [[ -n ${bname} ]]; then
|
||||
local infos="$(git_repo_status)${bname}%f"
|
||||
print " $infos"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -84,7 +74,7 @@ function zle-line-init zle-line-finish zle-keymap-select {
|
|||
zle -R
|
||||
}
|
||||
|
||||
function prompt_minimal_precmd() {
|
||||
prompt_minimal_precmd() {
|
||||
zle -N zle-line-init
|
||||
zle -N zle-keymap-select
|
||||
zle -N zle-line-finish
|
||||
|
@ -93,7 +83,7 @@ function prompt_minimal_precmd() {
|
|||
RPROMPT='$(minimal_path)$(minimal_git)'
|
||||
}
|
||||
|
||||
function prompt_minimal_setup() {
|
||||
prompt_minimal_setup() {
|
||||
prompt_char="❯"
|
||||
on_color="%F{green}"
|
||||
off_color="%f"
|
||||
|
|
|
@ -9,97 +9,95 @@
|
|||
|
||||
export VIRTUAL_ENV_DISABLE_PROMPT=1
|
||||
|
||||
function virtualenv_info {
|
||||
[ $VIRTUAL_ENV ] && print '('${fg[blue]}`basename $VIRTUAL_ENV`%{${reset_color}%}') '
|
||||
virtualenv_info() {
|
||||
[ ${VIRTUAL_ENV} ] && print '('${fg[blue]}${VIRTUAL_ENV:t}%{${reset_color}%}') '
|
||||
}
|
||||
|
||||
function steeef_preexec {
|
||||
case "$(history $HISTCMD)" in
|
||||
*git*)
|
||||
PR_GIT_UPDATE=1
|
||||
;;
|
||||
*svn*)
|
||||
PR_GIT_UPDATE=1
|
||||
;;
|
||||
esac
|
||||
steeef_preexec() {
|
||||
case "$(history $HISTCMD)" in
|
||||
*git*)PR_GIT_UPDATE=1
|
||||
;;
|
||||
*svn*)PR_GIT_UPDATE=1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function steeef_chpwd {
|
||||
PR_GIT_UPDATE=1
|
||||
steeef_chpwd() {
|
||||
PR_GIT_UPDATE=1
|
||||
}
|
||||
|
||||
function prompt_steeef_precmd {
|
||||
if [[ -n "$PR_GIT_UPDATE" ]] ; then
|
||||
# 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
|
||||
PR_GIT_UPDATE=1
|
||||
FMT_BRANCH="(%{$turquoise%}%b%u%c%{$hotpink%}●${PR_RST})"
|
||||
else
|
||||
FMT_BRANCH="(%{$turquoise%}%b%u%c${PR_RST})"
|
||||
fi
|
||||
zstyle ':vcs_info:*:prompt:*' formats "${FMT_BRANCH} "
|
||||
|
||||
vcs_info 'prompt'
|
||||
PR_GIT_UPDATE=
|
||||
prompt_steeef_precmd() {
|
||||
if [[ -n "$PR_GIT_UPDATE" ]] ; then
|
||||
# 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
|
||||
PR_GIT_UPDATE=1
|
||||
FMT_BRANCH="(%{$turquoise%}%b%u%c%{$hotpink%}●${PR_RST})"
|
||||
else
|
||||
FMT_BRANCH="(%{$turquoise%}%b%u%c${PR_RST})"
|
||||
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}%}
|
||||
$ '
|
||||
}
|
||||
|
||||
function prompt_steeef_setup {
|
||||
#use extended color pallete if available
|
||||
if [[ ${TERM} == *256* || ${TERM} == *rxvt* ]]; then
|
||||
turquoise="%F{81}"
|
||||
orange="%F{166}"
|
||||
purple="%F{135}"
|
||||
hotpink="%F{161}"
|
||||
limegreen="%F{118}"
|
||||
else
|
||||
turquoise="%F{cyan}"
|
||||
orange="%F{yellow}"
|
||||
purple="%F{magenta}"
|
||||
hotpink="%F{red}"
|
||||
limegreen="%F{green}"
|
||||
fi
|
||||
prompt_steeef_setup() {
|
||||
#use extended color pallete if available
|
||||
if [[ ${TERM} == *256* || ${TERM} == *rxvt* ]]; then
|
||||
turquoise="%F{81}"
|
||||
orange="%F{166}"
|
||||
purple="%F{135}"
|
||||
hotpink="%F{161}"
|
||||
limegreen="%F{118}"
|
||||
else
|
||||
turquoise="%F{cyan}"
|
||||
orange="%F{yellow}"
|
||||
purple="%F{magenta}"
|
||||
hotpink="%F{red}"
|
||||
limegreen="%F{green}"
|
||||
fi
|
||||
|
||||
# enable VCS systems you use
|
||||
zstyle ':vcs_info:*' enable git svn
|
||||
# enable VCS systems you use
|
||||
zstyle ':vcs_info:*' enable git svn
|
||||
|
||||
# check-for-changes can be really slow.
|
||||
# you should disable it, if you work with large repositories
|
||||
zstyle ':vcs_info:*:prompt:*' check-for-changes true
|
||||
# check-for-changes can be really slow.
|
||||
# you should disable it, if you work with large repositories
|
||||
zstyle ':vcs_info:*:prompt:*' check-for-changes true
|
||||
|
||||
# set 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
|
||||
PR_RST="%f"
|
||||
FMT_BRANCH="(%{$turquoise%}%b%u%c${PR_RST})"
|
||||
FMT_ACTION="(%{$limegreen%}%a${PR_RST})"
|
||||
FMT_UNSTAGED="%{$orange%}●"
|
||||
FMT_STAGED="%{$limegreen%}●"
|
||||
# set 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
|
||||
PR_RST="%f"
|
||||
FMT_BRANCH="(%{$turquoise%}%b%u%c${PR_RST})"
|
||||
FMT_ACTION="(%{$limegreen%}%a${PR_RST})"
|
||||
FMT_UNSTAGED="%{$orange%}●"
|
||||
FMT_STAGED="%{$limegreen%}●"
|
||||
|
||||
zstyle ':vcs_info:*:prompt:*' unstagedstr "${FMT_UNSTAGED}"
|
||||
zstyle ':vcs_info:*:prompt:*' stagedstr "${FMT_STAGED}"
|
||||
zstyle ':vcs_info:*:prompt:*' actionformats "${FMT_BRANCH}${FMT_ACTION}"
|
||||
zstyle ':vcs_info:*:prompt:*' formats "${FMT_BRANCH}"
|
||||
zstyle ':vcs_info:*:prompt:*' nvcsformats ""
|
||||
zstyle ':vcs_info:*:prompt:*' unstagedstr "${FMT_UNSTAGED}"
|
||||
zstyle ':vcs_info:*:prompt:*' stagedstr "${FMT_STAGED}"
|
||||
zstyle ':vcs_info:*:prompt:*' actionformats "${FMT_BRANCH}${FMT_ACTION}"
|
||||
zstyle ':vcs_info:*:prompt:*' formats "${FMT_BRANCH}"
|
||||
zstyle ':vcs_info:*:prompt:*' nvcsformats ""
|
||||
|
||||
PR_GIT_UPDATE=1
|
||||
PR_GIT_UPDATE=1
|
||||
|
||||
autoload -Uz add-zsh-hook
|
||||
autoload -Uz vcs_info
|
||||
autoload -Uz colors && colors
|
||||
autoload -Uz add-zsh-hook
|
||||
autoload -Uz vcs_info
|
||||
autoload -Uz colors && colors
|
||||
|
||||
add-zsh-hook preexec steeef_preexec
|
||||
add-zsh-hook chpwd steeef_chpwd
|
||||
add-zsh-hook precmd prompt_steeef_precmd
|
||||
prompt_opts=(cr subst percent)
|
||||
add-zsh-hook preexec steeef_preexec
|
||||
add-zsh-hook chpwd steeef_chpwd
|
||||
add-zsh-hook precmd prompt_steeef_precmd
|
||||
prompt_opts=(cr subst percent)
|
||||
}
|
||||
|
||||
prompt_steeef_setup "$@"
|
||||
|
|
Loading…
Reference in a new issue