summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--01_Functions.zsh8
-rw-r--r--11_Prompts.zsh91
2 files changed, 51 insertions, 48 deletions
diff --git a/01_Functions.zsh b/01_Functions.zsh
index 58a4ba5..3d1221d 100644
--- a/01_Functions.zsh
+++ b/01_Functions.zsh
@@ -87,13 +87,13 @@ get_git_status ()
if [ "$(git-rev-parse --git-dir)" == "." ]
then
- my_git_status="$COLOR_GIT_MANAGMENT"
+ my_git_status="$git_colors[managment_folder]"
elif [ "$(git-diff --cached 2>&- | grep '^diff ')" != "" ] ; then
- my_git_status="$COLOR_GIT_CACHED"
+ my_git_status="$git_colors[cached]"
elif [ "$(git-ls-files -m 2>&-)" != "" ] ; then
- my_git_status="$COLOR_GIT_NOT_UP_TO_DATE"
+ my_git_status="$git_colors[not_up_to_date]"
else
- my_git_status="$COLOR_GIT_UP_TO_DATE"
+ my_git_status="$git_colors[up_to_date]"
fi
echo $my_git_status
diff --git a/11_Prompts.zsh b/11_Prompts.zsh
index 0baea0e..babb165 100644
--- a/11_Prompts.zsh
+++ b/11_Prompts.zsh
@@ -21,17 +21,19 @@
#
# I'm storing the resulting dominant color in $GENERIC
+typeset -A prompt_colors git_colors mail_colors
+
PS1_ROOT=${PS1_ROOT:-$color[red]}
PS1_USER=${PS1_USER:-$color[blue]}
PS1_USER_SSH=${PS1_USER_SSH:-$color[magenta]}
-GENERIC=`print -Pn "%(! $PS1_ROOT $PS1_USER)"`
+prompt_colors[generic]=`print -Pn "%(! $PS1_ROOT $PS1_USER)"`
normal_user && if ( [ "$SSH_TTY" != "" ] )
then
# This allows us to easily distinguish shells
# which really are on the local machine or not.
# That's so good, use it ! :-)
- GENERIC=${PS1_USER_SSH:-$GENERIC}
+ prompt_colors[generic]=${PS1_USER_SSH:-$prompt_colors[generic]}
fi
c_=[
@@ -41,39 +43,40 @@ _C="$_c%}"
set_prompt_colors ()
{
- local generic=${1:-$GENERIC}
+ prompt_colors[generic]=${1:-$prompt_colors[generic]}
## Les couleurs !! ##
- COLOR_PATH="$color[reset];$generic;$color[bold]" # pwd
- #COLOR_TERM="$color[reset];$generic" # tty
- COLOR_USER="$color[reset];$generic" # login
- COLOR_HOST="$color[reset];$generic" # hostname
- #COLOR_HIST="$color[reset]" # history number
- COLOR_AROB="$color[reset];1;%(! $color[bold]; )$generic" # <login>@<hostname>
- COLOR_DIES="$color[reset];$generic" # the bottom-end of the prompt
- COLOR_DOUBLEDOT="$color[reset];" # separates pwd from git-branch
- #COLOR_PAREN="$color[reset];$color[cyan]" # parenthesis (around tty)
- COLOR_MAIL="$color[reset];$color[yellow];$color[bold]" # mail received
- COLOR_LISTES="$color[reset];$color[red];$color[bold]" # less important mail received
- COLOR_BAR="$color[reset];$generic;$color[bold]" # horizontal bar
- COLOR_BRACES=$COLOR_BAR # braces (around date)
- COLOR_ERRR="$color[bold];$color[yellow]" # error code
- COLOR_DATE="$color[reset];$generic" # full date
-
- COLOR_CMD="$color[reset]" # command prompt
- COLOR_EXEC="$color[reset]" # command output
-
- COLOR_BRANCH_OR_REV="$color[reset];$generic" # up-to-date
- COLOR_NOT_UP_TO_DATE="$color[reset];$color[green];$color[bold]" # not up to date
- COLOR_TO_BE_COMMITED="$color[reset];$color[yellow];$color[bold]" # changes in cache
-
- COLOR_GIT_MANAGMENT="$color[reset];$color[red];$color[bold]" # .git/... folder browsing
- COLOR_GIT_CACHED="$color[reset];$COLOR_TO_BE_COMMITED" # git changes in cache
- COLOR_GIT_NOT_UP_TO_DATE="$color[reset];$COLOR_NOT_UP_TO_DATE" # git changes in working tree
- COLOR_GIT_UP_TO_DATE="$color[reset];$generic" # git up-to-date
+ prompt_colors[path]="$color[none];$prompt_colors[generic];$color[bold]" # pwd
+ #prompt_colors[term]="$color[none];$prompt_colors[generic]" # tty
+ prompt_colors[user]="$color[none];$prompt_colors[generic]" # login
+ prompt_colors[host]="$color[none];$prompt_colors[generic]" # hostname
+ #prompt_colors[hist]="$color[none]" # history number
+ prompt_colors[arob]="$color[none];$color[bold];$prompt_colors[generic]" # <login>@<hostname>
+ prompt_colors[dies]="$color[none];$prompt_colors[generic]" # the bottom-end of the prompt
+ prompt_colors[doubledot]="$color[none];" # separates pwd from git-branch
+ #prompt_colors[paren]="$color[none];$color[cyan]" # parenthesis (around tty)
+ prompt_colors[bar]="$color[none];$prompt_colors[generic];$color[bold]" # horizontal bar
+ prompt_colors[braces]=$prompt_colors[bar] # braces (around date)
+ prompt_colors[error]="$color[bold];$color[yellow]" # error code
+ prompt_colors[date]="$color[none];$prompt_colors[generic]" # full date
+
+ prompt_colors[cmd]="$color[none]" # command prompt
+ prompt_colors[exec]="$color[none]" # command output
+
+ mail_colors[unread]="$color[none];$color[yellow];$color[bold]" # mail received
+ mail_colors[listes]="$color[none];$color[red];$color[bold]" # less important mail received
+
+ prompt_colors[up_to_date]="$color[none];$prompt_colors[generic]" # up-to-date
+ prompt_colors[not_up_to_date]="$color[none];$color[green];$color[bold]" # not up to date
+ prompt_colors[to_be_commited]="$color[none];$color[yellow];$color[bold]" # changes in cache
+
+ git_colors[managment_folder]="$color[none];$color[red];$color[bold]" # .git/... folder browsing
+ git_colors[cached]="$prompt_colors[to_be_commited]" # git changes in cache
+ git_colors[not_up_to_date]="$prompt_colors[not_up_to_date]" # git changes in working tree
+ git_colors[up_to_date]="$prompt_colors[up_to_date]" # git up-to-date
}
-set_prompt_colors $GENERIC
+set_prompt_colors $prompt_colors[generic]
## Prompts
#
@@ -90,7 +93,7 @@ set_prompt_colors $GENERIC
preexec ()
{
term_title " ··· $(echo $1 | tr ' \n' ' ;' | sed 's/%/%%/g;s/\\/\\\\/g')"
- print -Pn "$C_$COLOR_EXEC$_C"
+ print -Pn "$C_$prompt_colors[exec]$_C"
}
expand_text()
@@ -110,11 +113,11 @@ new_precmd()
# [4] post-string
#
typeset -A ERROR DATE MAILS LOGIN HOST CWD GITINFO SVNINFO PRECMD
- ERROR[color] = $COLOR_ERROR
+ ERROR[color] = $prompt_colors[error]
ERROR[string] = "%(?;;%?)"
ERROR[pre] = "-"
ERROR[post] =
- ERROR[size] = ${#$(print -Pn $ERROR["pre"]$ERROR["string"]$ERROR["post"])}
+ ERROR[size] = ${#$(print -Pn $ERROR[pre]$ERROR[string]$ERROR[post])}
}
old_precmd()
@@ -122,18 +125,18 @@ old_precmd()
# Error
error=$(print -Pn "%(?;;-%?)")
ERRORSIZE=${#error}
- ERROR="%(?;;"$C_$COLOR_BAR$_C"-"$C_$COLOR_ERRR$_C"%?)"
+ ERROR="%(?;;"$C_$prompt_colors[bar]$_C"-"$C_$prompt_colors[error]$_C"%?)"
# Flush the term title
term_title
# Date
- DATE=$C_$COLOR_BRACES$_C"[ "$C_$COLOR_DATE$_C"%D{%a-%d-%b-%Y %H:%M:%S}"$C_$COLOR_BRACES$_C" ]"$C_$COLOR_BAR$_C"-"
+ 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_$COLOR_BAR$_C""-""$C_$COLOR_MAIL$_C""@" } else if (LISTES > 0) { print "$C_$COLOR_BAR$_C""-""$C_$COLOR_LISTES$_C""@" } }'`")
+ 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}
@@ -188,15 +191,15 @@ old_precmd()
# then we reduce the path until it reaches the last path element,
spaceleft=$(($spaceleft - $GITBRANCHSIZE))
[ $spaceleft -lt $minimalpathsize ] && spaceleft=$minimalpathsize
- GITBRANCH=${GITBRANCH:+$C_$COLOR_DOUBLEDOT$_C:$C_"$(get_git_status)"$_C$GITBRANCH}
- CURDIR="$C_$COLOR_PATH$_C%`echo $spaceleft`<..<"$MY_PATH"%<<$C_$color[reset]$_C"
+ 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_$COLOR_BAR$_C"$HBAR""$DATE
-"$C_$COLOR_USER$_C"%n"$C_$COLOR_AROB$_C"@"$C_$COLOR_HOST$_C"%m $CURDIR$GITBRANCH "$C_$COLOR_DIES$_C"%#"$C_$COLOR_CMD$_C" "
+ 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$GITBRANCH "$C_$prompt_colors[dies]$_C"%#"$C_$prompt_colors[cmd]$_C" "
}
@@ -213,7 +216,7 @@ chpwd()
# Prompt level 2
-PS2="$C_$color[yellow];$color[bold]$_C%_$C_$color[reset];$color[cyan];$color[bold]$_C>$C_$color[reset]$_C "
+PS2="$C_$color[yellow];$color[bold]$_C%_$C_$color[none];$color[cyan];$color[bold]$_C>$C_$color[none]$_C "
# Prompt level 3
PS3="?# "
@@ -222,8 +225,8 @@ PS3="?# "
PS4="+%N:%i> "
# Prompt de droite, pour l'heure et le code d'erreur de la dernière commande
-#RPS1="%(?;;"$C_$COLOR_ERRR$_C"%?"$C_$color[reset]$_C")"
+#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[reset]$_C ? Vous ne vouliez pas plutôt $C_$color[magenta]$_C%B'%r'%b$C_$color[reset]$_C ? [%BN%byae] "
+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] "