1
0
Fork 0
mirror of synced 2024-11-22 23:35:35 -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
ext-liquidprompt
prompt_opts=(cr subst percent)
}
function prompt_liquidprompt_preview() {
prompt_liquidprompt_preview() {
_lp_set_prompt
prompt_preview_theme liquidprompt
}
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
#
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"

View file

@ -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"

View file

@ -9,26 +9,24 @@
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 {
steeef_preexec() {
case "$(history $HISTCMD)" in
*git*)
PR_GIT_UPDATE=1
*git*)PR_GIT_UPDATE=1
;;
*svn*)
PR_GIT_UPDATE=1
*svn*)PR_GIT_UPDATE=1
;;
esac
}
function steeef_chpwd {
steeef_chpwd() {
PR_GIT_UPDATE=1
}
function prompt_steeef_precmd {
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
@ -48,7 +46,7 @@ function prompt_steeef_precmd {
$ '
}
function prompt_steeef_setup {
prompt_steeef_setup() {
#use extended color pallete if available
if [[ ${TERM} == *256* || ${TERM} == *rxvt* ]]; then
turquoise="%F{81}"