[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() {
|
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
|
|
||||||
|
|
|
@ -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"
|
||||||
|
|
|
@ -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"
|
||||||
|
|
|
@ -9,26 +9,24 @@
|
||||||
|
|
||||||
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*)
|
*svn*)PR_GIT_UPDATE=1
|
||||||
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
|
||||||
|
@ -48,7 +46,7 @@ function prompt_steeef_precmd {
|
||||||
$ '
|
$ '
|
||||||
}
|
}
|
||||||
|
|
||||||
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}"
|
||||||
|
|
Loading…
Reference in a new issue