summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugues Hiegel <hugues@hiegel.fr>2008-03-06 23:35:03 +0100
committerHugues Hiegel <hugues@hiegel.fr>2008-03-07 14:15:22 +0100
commitd568b1df9fe6f529f33386e780e0f9813ecf4911 (patch)
tree48bc5bb13cca1efec8cdb47cd4df3e7743a49311
parent8cddca0a5c4cf1f569ecaf49afc52113768d2045 (diff)
Very much more better :
get_git_branch() been optimized. returns the current git branch get_git_status() been optimized. returns colors code TODO : return an indicator which will be used to get the color code from an array term_title() prints titles inside screen and sets screens-titles too. colors codes use of zsh-builtin "autoload colors && colors" instead of computing fucking color codes :)
-rw-r--r--01_Functions.zsh68
-rw-r--r--10_Environment.zsh13
-rw-r--r--11_Prompts.zsh66
3 files changed, 71 insertions, 76 deletions
diff --git a/01_Functions.zsh b/01_Functions.zsh
index 81671c9..b2a9e2d 100644
--- a/01_Functions.zsh
+++ b/01_Functions.zsh
@@ -19,9 +19,15 @@ term_title()
[[ -t 1 ]] &&
case $TERM in
sun-cmd)
- print -Pn "\e]l%n@%m %~$1\e\\" ;;
+ print -Pn "\e]l%n@%m %~$1\e\\" # Never tested..
+ ;;
*term*|rxvt*)
- print -Pn "\e]0;%n@%m (%l) %~$1\a" ;;
+ print -Pn "\e]0;%n@%m (%l) %~$1\a" # Sets term title
+ ;;
+ screen)
+ print -Pn "\e]2;[SCREEN] %n@%m (%l) %~$1\a" # Sets term title
+ print -Pn "\ek%n@%m (%l) %~$1\e\\" # Sets screen title
+ ;;
*)
;;
esac
@@ -39,50 +45,44 @@ preprint()
get_git_branch ()
{
+ local my_git_branch
+
# Get current working GIT branch
my_git_branch="$(git-branch 2>&- | grep -E '^\* ' | cut -c3-)"
- # If not on a working GIT branch, get the named current commit-ish inside parenthesis
- [ "$my_git_branch" == "(no branch)" ] &&\
- my_git_branch="$(git-show --pretty=format:%H 2>&- | head -n1 | git-name-rev --stdin 2>&- | awk '{ print $2 }')"
+ if [ "$my_git_branch" != "" ]
+ then
+ # If not on a working GIT branch, get the named current commit-ish inside parenthesis
+ [ "$my_git_branch" == "(no branch)" ] &&\
+ my_git_branch="$(git-show --pretty=format:%H 2>&- | head -n1 | git-name-rev --stdin 2>&- | awk '{ print $2 }')"
- # If neither on a named commit-ish, show abbreviated commit-id
- [ "$my_git_branch" == "" ] &&\
- my_git_branch="($(git-show --pretty=format:%h 2>&- | head -n1)...)"
+ # If neither on a named commit-ish, show abbreviated commit-id
+ [ "$my_git_branch" == "" ] &&\
+ my_git_branch="($(git-show --pretty=format:%h 2>&- | head -n1)...)"
+ fi
echo $my_git_branch
}
-check_git_status ()
+# We *must* have previously checked that
+# we obtained a correct GIT branch with
+# a call to `get_git_branch`
+get_git_status ()
{
- ## GIT TRACKING ##
- if [ "$GITCHECK" != "no" -a "$(git-ls-files 2>&-)" != "" ]
+ local my_git_status
+
+ if ( echo ${(s:/:)PWD} | grep "\.\<git\>" >/dev/null )
then
- GITBRANCH=$(get_git_branch);
- if [ "$GITBRANCH" != "" ]
- then
- #preprint "Check git status..."
- #_git_status=$(git-status 2>&- | grep -E '^# ([[:alpha:]]+ )+(but not|to be)( [[:alpha:]]+)+:$')
- if [ "$(git-diff --cached 2>&- | grep '^diff ')" != "" ] ; then
- COLOR_GIT=$COLOR_TO_BE_COMMITED
- elif [ "$(git-ls-files -m 2>&-)" != "" ] ; then
- COLOR_GIT=$COLOR_NOT_UP_TO_DATE
- else
- COLOR_GIT=$COLOR_BRANCH_OR_REV
- fi
-
- # Here we are on a .git folder..
- if ( echo ${(s:/:)PWD} | grep "\.\<git\>" >/dev/null )
- then
- COLOR_GIT="$BOLD;$RED"
- fi
-
- fi
+ my_git_status="$color[red];$color[bold]"
+ elif [ "$(git-diff --cached 2>&- | grep '^diff ')" != "" ] ; then
+ my_git_status="$color[yellow];$color[bold]"
+ elif [ "$(git-ls-files -m 2>&-)" != "" ] ; then
+ my_git_status="$color[green];$color[bold]"
else
- GITBRANCH=""
+ my_git_status="$color[blue]"
fi
- GitBranch=${GITBRANCH:+:$GITBRANCH}
- GITBRANCH=${GITBRANCH:+$C_$COLOR_DOUBLEDOT$_C:$C_$COLOR_GIT$_C$GITBRANCH}
+
+ echo $my_git_status
}
normal_user ()
diff --git a/10_Environment.zsh b/10_Environment.zsh
index 9919756..79b57b2 100644
--- a/10_Environment.zsh
+++ b/10_Environment.zsh
@@ -25,17 +25,7 @@ KEYCHAIN=~/.keychain/$(hostname)-sh
# [ -f ${KEYCHAIN}-gpg ] && source ${KEYCHAIN}-gpg
## Colors
-VOID=0
-BOLD=1
-UNDERLINE=4
-color=0
-for COLOR in BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE
-do
- eval $COLOR=$[ $color + 30 ]
- eval BG_$COLOR=$[ $color + 40 ]
- color=$[ $color + 1 ]
-done
-unset color
+autoload colors && colors
## Variables d'environnement ``classiques''
#
@@ -51,6 +41,7 @@ export MANPATH=$MANPATH:~/man
export INFOPATH=$INFOPATH:~/info
[ "$DEBUG" = "yes" ] && export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}~/libs
[ "$DEBUG" = "yes" ] && export PKG_CONFIG_PATH=${PKG_CONFIG_PATH:+$PKG_CONFIG_PATH:}~/pkgconfig
+
## Nettoyage des précédentes variables pour supprimer les duplicata
typeset -gU PATH MANPATH INFOPATH PKG_CONFIG_PATH LD_LIBRARY_PATH
diff --git a/11_Prompts.zsh b/11_Prompts.zsh
index 21eb85d..4caddad 100644
--- a/11_Prompts.zsh
+++ b/11_Prompts.zsh
@@ -13,9 +13,9 @@
# - PS1_USER pour la couleur du prompt USER local
# - PS1_USER_SSH pour la couleur du prompt USER distant (en ssh)
-PS1_ROOT=${PS1_ROOT:-$RED}
-PS1_USER=${PS1_USER:-$BLUE}
-PS1_USER_SSH=${PS1_USER_SSH:-$MAGENTA}
+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)"`
normal_user && if ( [ "$SSH_TTY" != "" ] )
@@ -31,28 +31,28 @@ C_="%{$c_"
_C="$_c%}"
## Les couleurs !! ##
-COLOR_PATH="0;$GENERIC;$BOLD"
-COLOR_TERM="0;$GENERIC"
-COLOR_USER="0;$GENERIC"
-COLOR_HOST="0;$GENERIC"
-COLOR_HIST="$VOID"
-COLOR_AROB="0;1;%(! $BOLD; )$GENERIC"
-COLOR_DIES="0;$GENERIC"
-COLOR_DOUBLEDOT="0;%(! $VOID $VOID)"
-COLOR_PAREN="0;$CYAN"
-COLOR_MAIL="0;$YELLOW;$BOLD"
-COLOR_BAR="0;$GENERIC;$BOLD"
+COLOR_PATH="$color[none];$GENERIC;$color[bold]"
+COLOR_TERM="$color[none];$GENERIC"
+COLOR_USER="$color[none];$GENERIC"
+COLOR_HOST="$color[none];$GENERIC"
+COLOR_HIST="$color[reset]"
+COLOR_AROB="$color[none];1;%(! $color[bold]; )$GENERIC"
+COLOR_DIES="$color[none];$GENERIC"
+COLOR_DOUBLEDOT="$color[none];"
+COLOR_PAREN="$color[none];$color[cyan]"
+COLOR_MAIL="$color[none];$color[yellow];$color[bold]"
+COLOR_BAR="$color[none];$GENERIC;$color[bold]"
COLOR_BRACES=$COLOR_BAR
-COLOR_BRANCH_OR_REV="0;$GENERIC"
-COLOR_NOT_UP_TO_DATE="0;$GREEN;$BOLD"
-COLOR_TO_BE_COMMITED="0;$YELLOW;$BOLD"
+COLOR_BRANCH_OR_REV="$color[none];$GENERIC"
+COLOR_NOT_UP_TO_DATE="$color[none];$color[green];$color[bold]"
+COLOR_TO_BE_COMMITED="$color[none];$color[yellow];$color[bold]"
-COLOR_CMD="$VOID"
-COLOR_EXEC="$VOID"
+COLOR_CMD="$color[reset]"
+COLOR_EXEC="$color[reset]"
-COLOR_ERRR="$BOLD;$YELLOW"
-COLOR_DATE="0;$GENERIC"
+COLOR_ERRR="$color[bold];$color[yellow]"
+COLOR_DATE="$color[none];$color[standout];$GENERIC"
## Prompts
#
@@ -78,8 +78,6 @@ preexec ()
print -Pn "$C_$COLOR_EXEC$_C"
}
-GITCHECK=${GITCHECK:-}
-
expand_text()
{
print -Pn -- "$(echo $@ | sed 's/%{[^(%})]*%}//g')"
@@ -95,7 +93,12 @@ new_precmd()
# [3] pre-string
# [4] post-string
#
- typeset -A ERROR DATE MAILS LOGIN HOST CWD GITINFO SVNINFO PROMPT
+ typeset -A ERROR DATE MAILS LOGIN HOST CWD GITINFO SVNINFO PRECMD
+ ERROR[color] = $COLOR_ERROR
+ ERROR[string] = "%(?;;%?)"
+ ERROR[pre] = "-"
+ ERROR[post] =
+ ERROR[size] = ${#$(print -Pn $ERROR["pre"]$ERROR["string"]$ERROR["post"])}
}
old_precmd()
@@ -105,7 +108,7 @@ old_precmd()
ERRORSIZE=${#error}
ERROR="%(?;;"$C_$COLOR_BAR$_C"-"$C_$COLOR_ERRR$_C"%?)"
- 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_$COLOR_BRACES$_C"[ "$C_$COLOR_DATE$_C"%D{%a-%d-%b-%Y %H:%M:%S}"$C_$COLOR_BRACES$_C" ]"$C_$COLOR_BAR$_C"-"
# Flush the term title
term_title
@@ -120,7 +123,8 @@ old_precmd()
MAILSTATSIZE=${#MAILSTATEXPAND}
# get git status
- check_git_status
+ GITBRANCH=$(get_git_branch)
+ GITBRANCH=${GITBRANCH:+$C_$COLOR_DOUBLEDOT$_C:$C_$(get_git_status)$_C$GITBRANCH}
# First line of prompt, calculation of the remaining place
spaceleft=$((1 + $COLUMNS - $ERRORSIZE - $MAILSTATSIZE - $DATESIZE))
@@ -133,12 +137,12 @@ old_precmd()
#
## Second line of prompt : don't let the path garbage the entire line
MY_PATH="%(!.%d.%~)"
- spaceleft=`print -Pn "%n@%m $GitBranch $ ls -laCdtrux $(expand_text "$DATE")"`
+ spaceleft=`print -Pn "%n@%m $(expand_text $GITBRANCH) $ ls -laCdtrux $(expand_text "$DATE")"`
spaceleft=$(($COLUMNS - ${#spaceleft}))
minimalsize=`print -Pn "%1~"`
minimalsize=$((3 + ${#minimalsize}))
[ $spaceleft -lt $minimalsize ] && spaceleft=$minimalsize
- CURDIR="$C_$COLOR_PATH$_C%`echo $spaceleft`<..<"$MY_PATH"%<<$C_$VOID$_C"
+ CURDIR="$C_$COLOR_PATH$_C%`echo $spaceleft`<..<"$MY_PATH"%<<$C_$color[reset]$_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...
@@ -162,7 +166,7 @@ chpwd()
# Prompt level 2
-PS2="%{%}%B%_%b%{%}%B>%b%{%} "
+PS2="%{%}%B%_%b%{%}%B>%b%{[$color[none]m%} "
# Prompt level 3
PS3="?# "
@@ -171,8 +175,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_$VOID$_C")"
+#RPS1="%(?;;"$C_$COLOR_ERRR$_C"%?"$C_$color[reset]$_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] "
+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] "