From 1a53a4ba1d9581271adb09841baee5423df55ad9 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Thu, 20 Mar 2008 09:42:36 +0100 Subject: Colors defs moved from Prompts.zsh to Colors.zsh --- 12_Prompts.zsh | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 12_Prompts.zsh (limited to '12_Prompts.zsh') diff --git a/12_Prompts.zsh b/12_Prompts.zsh new file mode 100644 index 0000000..d9ae9fa --- /dev/null +++ b/12_Prompts.zsh @@ -0,0 +1,176 @@ +## +## Part of configuration files for Zsh 4 +## by Hugues Hiegel +## +## NO WARRANTY PROVIDED, USE AT YOUR OWN RISKS +## +## You are encouraged to use, modify, and redistribute +## these files with or without this notice. +## + +set_prompt_colors $prompt_colors[generic] + +## Prompts +# +# man zshmisc(1) +# + +## Automagic funcs +# +# chpwd : changement de répertoire +# preexec : avant d'exécuter une commande +# precmd : avant d'afficher le prompt +# + +preexec () +{ + term_title " ··· $(echo $1 | tr ' \n' ' ;' | sed 's/%/%%/g;s/\\/\\\\/g')" + print -Pn "$C_$prompt_colors[exec]$_C" +} + +expand_text() +{ + # strips the %{...%} + print -Pn -- "$(echo $@ | sed 's/%{[^(%})]*%}//g')" +} + +new_precmd() +{ + # + # Arrays + # [0] prompt-style string + # [1] total size + # [2] color + # [3] pre-string + # [4] post-string + # + typeset -A ERROR DATE MAILS LOGIN HOST CWD GITINFO SVNINFO PRECMD + ERROR[color] = $prompt_colors[error] + ERROR[string] = "%(?;;%?)" + ERROR[pre] = "-" + ERROR[post] = + ERROR[size] = ${#$(print -Pn $ERROR[pre]$ERROR[string]$ERROR[post])} +} + +old_precmd() +{ + # Error + error=$(print -Pn "%(?;;-%?)") + ERRORSIZE=${#error} + ERROR="%(?;;"$C_$prompt_colors[bar]$_C"-"$C_$prompt_colors[error]$_C"%?)" + + # Flush the term title + term_title + + # Date + DATE=$C_$prompt_colors[braces]$_C"[ "$C_$prompt_colors[date]$_C"%D{%a-%d-%b-%Y %H:%M:%S}"$C_$prompt_colors[braces]$_C" ]"$C_$prompt_colors[bar]$_C"-" + DATEEXPAND=$(expand_text "$DATE") + DATESIZE=${#DATEEXPAND} + + # Mailcheck + MAILSTAT=$(eval echo "`[ -s ~/.procmail/procmail.log ] && < ~/.procmail/procmail.log awk 'BEGIN {RS="From" ; HAM=-1 ; LISTES=0 } !/JUNK/ { HAM++ } /Listes|Newsletters|Notifications/ { LISTES++ } END { if ((HAM - LISTES) > 0) { print "$C_$prompt_colors[bar]$_C""-""$C_$mail_colors[unread]$_C""@" } else if (LISTES > 0) { print "$C_$prompt_colors[bar]$_C""-""$C_$mail_colors[listes]$_C""@" } }'`") + MAILSTATEXPAND=$(expand_text "$MAILSTAT") + MAILSTATSIZE=${#MAILSTATEXPAND} + + # First line of prompt, calculation of the remaining place + spaceleft=$((1 + $COLUMNS - $ERRORSIZE - $MAILSTATSIZE - $DATESIZE)) + + unset HBAR + for h in {1..$(($spaceleft - 1))} + do + HBAR=$HBAR- + done + + ## + ## Second line of prompt : don't let the path garbage the entire line + ## + + # get svn status + # + SVNREV=$(LC_ALL=C svn info 2>&- $PWD | awk '/^Revision: / {print $2}') + SVNREVSIZE=${#${SVNREV:+:r$SVNREV}} + if [ "$SVNREV" != "" ] + then + SVNSTATUS="$(svn status 2>&-)" + SVNSTATUS=${SVNSTATUS:+$prompt_colors[not_up_to_date]} + SVNSTATUS=${SVNSTATUS:-$prompt_colors[up_to_date]} + fi + SVNREV=${SVNREV:+$C_$prompt_colors[doubledot]$_C:$C_$SVNSTATUS$_C"r"$SVNREV} + + # get git status + # + GITBRANCH=$(get_git_branch) + GITBRANCHSIZE=${#GITBRANCH} + [ $GITBRANCHSIZE -gt 0 ] && GITBRANCHSIZE=$(($GITBRANCHSIZE)) + + MY_PATH="%(!.%d.%~)" + PATHSIZE=$(print -Pn $MY_PATH) + PATHSIZE=${#PATHSIZE} + spaceleft=`print -Pn "%n@%m $ ls -laCdtrux $(expand_text "$DATE")"` + spaceleft=$(($COLUMNS - ${#spaceleft})) + #minimalpathsize=`print -Pn "../%1~"` + #minimalpathsize=${#minimalpathsize} + minimalpathsize=10 + minimalgitsize=10 # git-abbrev-commit-ish... + if [ $GITBRANCHSIZE -gt 0 ] + then + if [ $spaceleft -lt $(( $PATHSIZE + $GITBRANCHSIZE )) ] + then + local unbreakablegittail + # reduce the git-branch until it is shrinked to $minimalgitsize characters max. + + if [ $GITBRANCH[-1] = ")" ] + then + unbreakablegittail=${${(M)GITBRANCH%\~*}} + [ "$unbreakablegittail" = "" -a $GITBRANCHSIZE -gt $minimalgitsize ] && unbreakablegittail=")" + fi + if [ $GITBRANCHSIZE -gt $minimalgitsize ] + then + GITBRANCHSIZE=$(( $spaceleft - $PATHSIZE )) + [ $GITBRANCHSIZE -lt $minimalgitsize ] && GITBRANCHSIZE=$minimalgitsize + fi + GITBRANCH=`print -Pn "%"$(($GITBRANCHSIZE - ${#unbreakablegittail}))">..>"${GITBRANCH%\~*}${unbreakablegittail:+"%"${#unbreakablegittail}"<<"$GITBRANCH}` + fi + fi + # then we reduce the path until it reaches the last path element, + spaceleft=$(($spaceleft - $GITBRANCHSIZE)) + [ $spaceleft -lt $minimalpathsize ] && spaceleft=$minimalpathsize + GITBRANCH=${GITBRANCH:+$C_$prompt_colors[doubledot]$_C:$C_"$(get_git_status)"$_C$GITBRANCH} + CURDIR="$C_$prompt_colors[path]$_C%`echo $spaceleft`<..<"$MY_PATH"%<<$C_$color[none]$_C" + +## Le prompt le plus magnifique du monde, et c'est le mien ! +# Affiche l'user, l'host, le tty et le pwd. Rien que ça... +# Note que pour le pwd, on n'affiche que les 4 derniers dossiers pour éviter +# de pourrir le fenêtre de terminal avec un prompt à rallonge. + PS1="$MAILSTAT""$ERROR"$C_$prompt_colors[bar]$_C"$HBAR""$DATE +"$C_$prompt_colors[user]$_C"%n"$C_$prompt_colors[arob]$_C"@"$C_$prompt_colors[host]$_C"%m $CURDIR$SVNREV$GITBRANCH "$C_$prompt_colors[dies]$_C"%#"$C_$prompt_colors[cmd]$_C" " + + +} + +precmd() +{ + old_precmd +} + +chpwd() +{ + which todo > /dev/null 2>&1 && todo +} + + +# Prompt level 2 +PS2="$C_$color[yellow];$color[bold]$_C%_$C_$color[none];$color[cyan];$color[bold]$_C>$C_$color[none]$_C " + +# Prompt level 3 +PS3="?# " + +# Prompt level 4 +PS4="+%N:%i> " + +# Prompt de droite, pour l'heure et le code d'erreur de la dernière commande +#RPS1="%(?;;"$C_$prompt_colors[error]$_C"%?"$C_$color[none]$_C")" + +# Ultime : prompt de correction :-) +SPROMPT="zsh: $C_$color[blue]$_C%B'%R'%b$C_$color[none]$_C ? Vous ne vouliez pas plutôt $C_$color[magenta]$_C%B'%r'%b$C_$color[none]$_C ? [%BN%byae] " + -- cgit v1.2.3 From c268cfc267a71254881a85975504f0a3e0e69815 Mon Sep 17 00:00:00 2001 From: Hugues Date: Thu, 20 Mar 2008 12:10:42 +0100 Subject: Correction colors --- 11_Colors.zsh | 6 +++++- 12_Prompts.zsh | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to '12_Prompts.zsh') diff --git a/11_Colors.zsh b/11_Colors.zsh index c76fd95..db68bb1 100644 --- a/11_Colors.zsh +++ b/11_Colors.zsh @@ -13,7 +13,7 @@ _c=m C_="%{$c_" _C="$_c%}" -typeset -A prompt_colors git_colors mail_colors +typeset -A prompt_colors git_colors mail_colors correct_colors # I hate kik00l0l colorized prompts, so I'm using a way to # give a dominant color for each part of the prompt, each of @@ -81,3 +81,7 @@ set_prompt_colors () } set_prompt_colors + +correct_colors[error]="$color[red];$color[bold]" +correct_colors[suggest]="$color[blue];$color[bold]" + diff --git a/12_Prompts.zsh b/12_Prompts.zsh index d9ae9fa..a5b7348 100644 --- a/12_Prompts.zsh +++ b/12_Prompts.zsh @@ -172,5 +172,5 @@ PS4="+%N:%i> " #RPS1="%(?;;"$C_$prompt_colors[error]$_C"%?"$C_$color[none]$_C")" # Ultime : prompt de correction :-) -SPROMPT="zsh: $C_$color[blue]$_C%B'%R'%b$C_$color[none]$_C ? Vous ne vouliez pas plutôt $C_$color[magenta]$_C%B'%r'%b$C_$color[none]$_C ? [%BN%byae] " +SPROMPT="zsh: $C_$correct_colors[error]$_C'%R'$C_$color[none]$_C ? Vous ne vouliez pas plutôt $C_$correct_colors[suggest]$_C'%r'$C_$color[none]$_C ? [%BN%byae] " -- cgit v1.2.3