From 32b91579bcb28239b34f6dd3f9e9ea3e00f08705 Mon Sep 17 00:00:00 2001 From: hugues Date: Wed, 18 Jul 2007 09:33:39 +0000 Subject: Wow that's so very much beautifuuuul :o) git-svn-id: svn+ssh://hugues@maison/opt/svn/private/hugues@466 a0e5b806-a6f9-0310-978d-cbce73f8a913 --- 01_Functions.zsh | 33 ----------------------- 11_Prompts.zsh | 82 +++++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 72 insertions(+), 43 deletions(-) diff --git a/01_Functions.zsh b/01_Functions.zsh index 29d7c60..2d2407a 100644 --- a/01_Functions.zsh +++ b/01_Functions.zsh @@ -8,39 +8,6 @@ ## these files with or without this notice. ## -term_title() -{ - [[ -t 1 ]] && - case $TERM in - sun-cmd) - print -Pn "\e]l%n@%m %~$1\e\\" ;; - *term*|rxvt*) - print -Pn "\e]0;%n@%m (%l) %~$1\a" ;; - esac -} - -_chpwd() -{ - term_title -} - -chpwd() -{ - _chpwd - which todo > /dev/null 2>&1 && todo -} - -precmd () -{ -## [[ -t 1 ]] && -# print -nP "%(?,,%{%}Foirage n°%{%}%?\n)%{%}" - _chpwd -} - -preexec () -{ - term_title " ··· $1" -} cmd_exists () { diff --git a/11_Prompts.zsh b/11_Prompts.zsh index 10f2f3b..d2c05d9 100644 --- a/11_Prompts.zsh +++ b/11_Prompts.zsh @@ -16,25 +16,33 @@ PS1_ROOT=${PS1_ROOT:-$RED} PS1_USER=${PS1_USER:-$BLUE} PS1_USER_SSH=${PS1_USER_SSH:-$MAGENTA} +MYCOLOR=$(print -Pn "%(! $PS1_ROOT $PS1_USER)") if ( [ "$SSH_TTY" != "" ] ) then # Permet de faire une distinction rapide entre les shells locaux # et les shells distants. C'est trop bon, mangez-en ! - PS1_USER=${PS1_USER_SSH:-$PS1_USER} + MYCOLOR=${PS1_USER_SSH:-$MYCOLOR} fi +c_=[ +_c=m + ## Les couleurs !! ## -COLOR_PATH="0;%(!.$PS1_ROOT.$BOLD;$PS1_USER)" -COLOR_TERM="0;%(!.$PS1_ROOT.$PS1_USER)" -COLOR_USER="0;%(!.$PS1_ROOT.$PS1_USER)" -COLOR_HOST="0;%(!.$PS1_ROOT.$PS1_USER)" +COLOR_PATH="0;%(! $BOLD;)$MYCOLOR" +COLOR_TERM="0;$MYCOLOR" +COLOR_USER="0;$MYCOLOR" +COLOR_HOST="0;$MYCOLOR" COLOR_HIST=$VOID -COLOR_AROB="0;1;%(!.$BOLD;$PS1_ROOT.$PS1_USER)" -COLOR_DIES="0;%(!.$BOLD;$PS1_ROOT.$PS1_USER)" +COLOR_AROB="0;1;%(! $BOLD; )$MYCOLOR" +COLOR_DIES="0;%(! $BOLD; )" +COLOR_DOUBLEDOT="0;%(! $VOID $MYCOLOR)" +COLOR_BRANCH="0;%(! $BOLD; )$MYCOLOR" +COLOR_BRACES="0;$CYAN" +COLOR_PAREN="0;$CYAN" COLOR_ERRR="$BOLD;$RED" -COLOR_DATE="0;%(!.$PS1_ROOT.$PS1_USER)" +COLOR_DATE="0;$MYCOLOR" ## Prompts # @@ -45,11 +53,65 @@ COLOR_DATE="0;%(!.$PS1_ROOT.$PS1_USER)" # classiques pour permettre de configurer, par exemple, les couleurs par défaut # dans ces fichiers. +## Automagic funcs +# +# Fonctions exécutées automatiquement sous certaines conditions +# +# chpwd : changement de répertoire +# preexec : avant d'exécuter une commande +# precmd : avant d'afficher le prompt +# + +term_title() +{ + [[ -t 1 ]] && + case $TERM in + sun-cmd) + print -Pn "\e]l%n@%m %~$1\e\\" ;; + *term*|rxvt*) + print -Pn "\e]0;%n@%m (%l) %~$1\a" ;; + esac +} + +preexec () +{ + term_title " ··· $1" +} + +precmd () +{ +## [[ -t 1 ]] && +# print -nP "%(?,,%{%}Foirage n°%{%}%?\n)%{%}" + term_title + + DATE=$(date "+%H:%M:%S-%d/%m/%Y") + if [ ! $? -eq 0 ] + then + ERROR=$? + else + ERROR= + fi + HBAR= + for i in {1..$(($COLUMNS - ${#DATE} - ${#ERROR} - 2))} + do + HBAR=$HBAR- + done + + echo "$c_$BOLD;$MYCOLOR$_c-$c_$COLOR_ERRR$_c$ERROR$c_$MYCOLOR$_c$HBAR$DATE-$c_$VOID$_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=""$C_$COLOR_USER$_C"%n"$C_$COLOR_AROB$_C"@"$C_$COLOR_HOST$_C"%m"$C_$VOID$_C" ("$C_$COLOR_TERM$_C"%y"$C_$VOID$_C") ["$C_$COLOR_PATH$_C"%(!.%d.%(5~:.../:)%4~)"$C_$VOID$_C"]"${LD_PRELOAD:t:s/lib//:r}" "$C_$COLOR_HIST$_C"%h"$C_$COLOR_DIES$_C"%#"$C_$VOID$_C" " +chpwd() +{ + term_title + which todo > /dev/null 2>&1 && todo + + PS1=""$C_$COLOR_USER$_C"%n"$C_$COLOR_AROB$_C"@"$C_$COLOR_HOST$_C"%m "$C_$COLOR_PAREN$_C"("$C_$COLOR_TERM$_C"%y"$C_$COLOR_PAREN$_C") "$C_$COLOR_BRACES$_C"["$C_$COLOR_PATH$_C"%(!.%d.%(5~:.../:)%4~)"$C_$VOID$_C${$(git branch):+$C_$COLOR_DOUBLEDOT$_C:$C_$COLOR_BRANCH$_C$(git branch | cut -c3-)}$C_$COLOR_BRACES$_C"]"$C_$VOID$_C${LD_PRELOAD:t:s/lib//:r}" "$C_$COLOR_HIST$_C"%h"$C_$COLOR_DIES$_C"%#"$C_$VOID$_C" " +} + # Prompt level 2 PS2="%{%}%B%_%b%{%}%B>%b%{%} " @@ -61,7 +123,7 @@ 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_$VOID$_C") "$C_$COLOR_DATE$_C"%D{%H:%M:%S %d/%m/%Y}"$C_$VOID$_C"" +RPS1="%(?;;"$C_$COLOR_ERRR$_C"%?"$C_$VOID$_C")" # Ultime : prompt de correction :-) SPROMPT="zsh: $C_$BLUE$_C%B'%R'%b$C_$VOID$_C ? Vous ne vouliez pas plutôt $C_$MAGENTA$_C%B'%r'%b$C_$VOID$_C ? [%BN%byae] " -- cgit v1.2.3