From 4fd79792121c7df347f0177809754129b2087a76 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Thu, 8 Mar 2012 13:18:24 +0100 Subject: [Prompt] Compil. --- 12_Prompts.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/12_Prompts.zsh b/12_Prompts.zsh index 81c6dc8..13318cf 100644 --- a/12_Prompts.zsh +++ b/12_Prompts.zsh @@ -339,7 +339,7 @@ __yeah_prompt () __two_lines_prompt () { - __compilation + __compilation 2>&- ## 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... # -- cgit v1.2.3 From 0e11bf5a4724abde44795545f09419d4bc4247be Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Fri, 9 Mar 2012 10:38:32 +0100 Subject: [Prompts] Huge cleanup --- 12_Prompts.zsh | 116 ++++++++++++++++++--------------------------------------- 1 file changed, 36 insertions(+), 80 deletions(-) diff --git a/12_Prompts.zsh b/12_Prompts.zsh index 13318cf..6fece37 100644 --- a/12_Prompts.zsh +++ b/12_Prompts.zsh @@ -66,6 +66,7 @@ __hbar() { if [ $COLUMNS != $_COLUMNS_OLD ] then + _COLUMNS_OLD=$COLUMNS unset HBAR HBAR=$T_ for h in {1..$COLUMNS} @@ -76,7 +77,7 @@ __hbar() fi } -preexec () +_preexec () { __term_title "$(echo $1 | tr ' \n' ' ;' | sed 's/%/%%/g;s/\\/\\\\/g;s/;$//')" @@ -113,7 +114,7 @@ __update_prompt_elements() # Error [ "$DEBUG" = "yes" ] && echo -n " Error code..." ERRORSIZE=${#ERROR} - ERROR="%(?;;"$C_$_prompt_colors[error]$_C"%?)" + ERROR=${ERROR:+$C_$_prompt_colors[error]$_C$ERROR} [ "$DEBUG" = "yes" ] && echo [ "$DEBUG" = "yes" ] && echo -n " Term title..." @@ -123,18 +124,16 @@ __update_prompt_elements() __set_prompt_date + [ "$DEBUG" = "yes" ] && echo -n " Horizontal bar..." + __hbar + [ "$DEBUG" = "yes" ] && echo + + + [ "$DEBUG" = "yes" ] && echo -n " Agents..." # GPG/SSH agents AGENTS="" - local _is_multibyte_compliant - if ( echo ${(k)options} | grep "multibyte" >/dev/null ) && [ "$options[multibyte]" = "on" ] - then - _is_multibyte_compliant="yes it is !" - else - _is_multibyte_compliant="" - fi - [ "$DEBUG" = "yes" ] && echo && echo -n " ......SSH" # Check ssh-agent only if the env socket has been set and is accessible if [ -S "$SSH_AUTH_SOCK" ] @@ -147,7 +146,7 @@ __update_prompt_elements() # That's a local agent if [ "$SSH_AGENT_KEYLIST" != "" ] then - AgentChar=${AGENT_WITH_KEYS:-$( [ $_is_multibyte_compliant ] && echo "✔" || echo "$" )} + AgentChar=${AGENT_WITH_KEYS:-✔} AGENTS="" for i in $(echo $SSH_AGENT_KEYLIST | cut -d' ' -f3 ) do @@ -155,7 +154,7 @@ __update_prompt_elements() done else AGENTCOLOR="empty" - AgentChar=${AGENT_EMPTY:-$( [ $_is_multibyte_compliant ] && echo "✘" || echo "S" )} + AgentChar=${AGENT_EMPTY:-✘} AGENTS=$C_$_agent_colors[$AGENTCOLOR]$_C"$AgentChar" fi else @@ -163,10 +162,10 @@ __update_prompt_elements() if [ "$SSH_AGENT_KEYLIST" != "" ] then AGENTCOLOR="has_remote_keys" - AgentChar=${AGENT_SOCK_WITH_KEYS:-$( [ $_is_multibyte_compliant ] && echo "✓" || echo "@" )} + AgentChar=${AGENT_SOCK_WITH_KEYS:-✓} else AGENTCOLOR="remote_empty" - AgentChar=${AGENT_SOCK_EMPTY:-$( [ $_is_multibyte_compliant ] && echo "✗" || echo "O" )} + AgentChar=${AGENT_SOCK_EMPTY:-✗} fi AGENTS=$C_$_agent_colors[$AGENTCOLOR]$_C"$AgentChar" fi @@ -179,60 +178,13 @@ __update_prompt_elements() if [ "`strings /proc/$GPG_AGENT_PID/cmdline | head -n1`" = "gpg-agent" ] then AGENTCOLOR="has_keys" - AGENTS=$AGENTS$C_$_agent_colors[$AGENTCOLOR]$_C${GPG_AGENT_RUNNING:-$( [ $_is_multibyte_compliant ] && echo "⚡" || echo "G" )} + AGENTS=$AGENTS$C_$_agent_colors[$AGENTCOLOR]$_C${GPG_AGENT_RUNNING:-⚡} fi fi AGENTSSIZE=$(__expand_text $AGENTS) AGENTSSIZE=$#AGENTSSIZE [ "$DEBUG" = "yes" ] && echo - if [ -e /proc/pmu/battery_0 ] - then - [ "$DEBUG" = "yes" ] && echo -n " Battery..." - - POWERADAPTER=$(grep "^AC Power" /proc/pmu/info | cut -c26) - - typeset -A battery - battery[remaining]=$(grep "^time rem" /proc/pmu/battery_0 | cut -c14- ) - battery[remain_hrs]=$(( $battery[remaining] / 3600 )) - battery[remain_min]=$(( ($battery[remaining] - ( $battery[remain_hrs] * 3600 )) / 60 )) - [ "$battery[remain_min]" -lt 10 ] && battery[remain_min]="0"$battery[remain_min] - battery[remains]=$battery[remain_hrs]"h"$battery[remain_min] - - BATTERYSIZE=$(( ${#battery[remains]} + 1 )) - - battery[load]=$(grep "^current" /proc/pmu/battery_0 | cut -c14- ) - - if [ $POWERADAPTER -ne 0 ] - then - battery[color]="charging" - if [ $battery[load] -eq 0 ] - then - ## Battery full - BATTERYSIZE=2 - battery[remains]="⚡" - fi - else - if [ $battery[remaining] -lt 659 ] - then - battery[color]="critical" - else - battery[color]="uncharging" - fi - fi - BATTERY=$C_$_prompt_colors[bar]$_C$T_"$_tq_"$_T$C_$_battery_colors[$battery[color]]$_C"$battery[remains]" - unset BATTERY - - [ "$DEBUG" = "yes" ] && echo - else - BATTERY= - BATTERYSIZE=0 - fi - - [ "$DEBUG" = "yes" ] && echo -n " Horizontal bar..." - # First line of prompt, calculation of the remaining place - __hbar - [ "$DEBUG" = "yes" ] && echo ## ## Second line of prompt : don't let the path garbage the entire line @@ -246,23 +198,26 @@ __update_prompt_elements() then CVSTAG=$(test -e CVS/Tag && cat CVS/Tag || basename $(cat CVS/Root 2>&- || echo "HEAD") ) CVSTAG=${CVSTAG:+ $C_$_gcl_colors[uptodate]$_C$CVSTAG} - fi + fi - # get svn status - # - [ "$DEBUG" = "yes" ] && echo -n " SVN status..." - SVNREV=$(LC_ALL=C svn info 2>&- $PWD | awk '/^Revision: / {print $2}') - SVNREVSIZE=${#${SVNREV:+ r$SVNREV}} - if [ "$SVNREV" != "" ] - then - if [ ! -z "$CHECK_SVN_STATUS" ] - then - SVNSTATUS="$(svn diff 2>&-)" - SVNSTATUS=${${SVNSTATUS:+$_gcl_colors[changed]}:-$_gcl_colors[uptodate]} - fi - fi - SVNREV=${SVNREV:+$C_$_prompt_colors[doubledot]$_C $C_$SVNSTATUS$_C"r"$SVNREV} - [ "$DEBUG" = "yes" ] && echo + if [ -d .svn ] + then + # get svn status + # + [ "$DEBUG" = "yes" ] && echo -n " SVN status..." + SVNREV=$(LC_ALL=C svn info 2>&- $PWD | awk '/^Revision: / {print $2}') + SVNREVSIZE=${#${SVNREV:+ r$SVNREV}} + if [ "$SVNREV" != "" ] + then + if [ ! -z "$CHECK_SVN_STATUS" ] + then + SVNSTATUS="$(svn diff 2>&-)" + SVNSTATUS=${${SVNSTATUS:+$_gcl_colors[changed]}:-$_gcl_colors[uptodate]} + fi + fi + SVNREV=${SVNREV:+$C_$_prompt_colors[doubledot]$_C $C_$SVNSTATUS$_C"r"$SVNREV} + [ "$DEBUG" = "yes" ] && echo + fi # get hg status [ "$DEBUG" = "yes" ] && echo -n " HG status..." @@ -318,6 +273,8 @@ __update_prompt_elements() [ "$DEBUG" = "yes" ] && echo VCSBRANCH=$CVSTAG$SVNREV$GITBRANCH$HGBRANCH + + __compilation 2>&- } __redefine_prompt () @@ -339,7 +296,6 @@ __yeah_prompt () __two_lines_prompt () { - __compilation 2>&- ## 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... # @@ -378,7 +334,7 @@ fi precmd() { # this MUST BE the real first operation else we lose the error code... - ERROR=$(print -Pn "%(?;;-%?)") + ERROR=$(print -Pn "%(?;;%?)") __update_prompt_elements __redefine_prompt -- cgit v1.2.3 From b15c129a1fccf04927b6b4eb4a9573ce46b80c31 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Fri, 9 Mar 2012 10:55:26 +0100 Subject: [Prompt] I finally corrected this fucking precmd managment !!! --- 12_Prompts.zsh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/12_Prompts.zsh b/12_Prompts.zsh index 6fece37..9e372b1 100644 --- a/12_Prompts.zsh +++ b/12_Prompts.zsh @@ -77,7 +77,7 @@ __hbar() fi } -_preexec () +preexec () { __term_title "$(echo $1 | tr ' \n' ' ;' | sed 's/%/%%/g;s/\\/\\\\/g;s/;$//')" @@ -87,12 +87,11 @@ _preexec () __hbar __redefine_prompt - local lines="$(($(__expand_text "$PROMPT$1" | sed "s/\\(.\{0,$COLUMNS\}\\)/\\1\\n/g" | wc -l)))" - for i in {1..$lines} ; print -Pn "\e[1A\e[2K" - print -Pn "\r$PROMPT" - print -Pn "$C_$color[cyan]$_C" - print "${(q)1}" | sed "s/'$//;s/^'//" - + local lines="$(($( (__expand_text "$PROMPT";__expand_text "$1") | sed "s/\\(.\{0,$COLUMNS\}\\)/\\1\\n/g" | wc -l)))" + tput sc + for i in {1..$lines} ; tput cuu1 + print -Pn "$PROMPT" + tput rc print -Pn "$C_$_prompt_colors[exec]$_C" } -- cgit v1.2.3 From 6f7138379a0b764781a7bc2d7bae3c77d23adbe9 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Fri, 9 Mar 2012 11:29:01 +0100 Subject: Cleanup --- 12_Prompts.zsh | 76 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/12_Prompts.zsh b/12_Prompts.zsh index 9e372b1..13ec48c 100644 --- a/12_Prompts.zsh +++ b/12_Prompts.zsh @@ -64,17 +64,17 @@ __expand_text() export _COLUMNS_OLD=0 __hbar() { - if [ $COLUMNS != $_COLUMNS_OLD ] - then - _COLUMNS_OLD=$COLUMNS - unset HBAR - HBAR=$T_ - for h in {1..$COLUMNS} - do - HBAR=${HBAR}$C_$_prompt_colors[generic]$_C$_tq_ - done - HBAR=$HBAR$_T - fi + if [ $COLUMNS != $_COLUMNS_OLD ] + then + _COLUMNS_OLD=$COLUMNS + unset HBAR + HBAR=$T_ + for h in {1..$COLUMNS} + do + HBAR=${HBAR}$C_$_prompt_colors[generic]$_C$_tq_ + done + HBAR=$HBAR$_T + fi } preexec () @@ -84,14 +84,14 @@ preexec () _prompt_colors[date]=$_date_colors[exec] __set_prompt_date x _prompt_colors[date]=$_date_colors[normal] - __hbar + __hbar __redefine_prompt local lines="$(($( (__expand_text "$PROMPT";__expand_text "$1") | sed "s/\\(.\{0,$COLUMNS\}\\)/\\1\\n/g" | wc -l)))" - tput sc + tput sc for i in {1..$lines} ; tput cuu1 print -Pn "$PROMPT" - tput rc + tput rc print -Pn "$C_$_prompt_colors[exec]$_C" } @@ -124,7 +124,7 @@ __update_prompt_elements() __set_prompt_date [ "$DEBUG" = "yes" ] && echo -n " Horizontal bar..." - __hbar + __hbar [ "$DEBUG" = "yes" ] && echo @@ -197,26 +197,26 @@ __update_prompt_elements() then CVSTAG=$(test -e CVS/Tag && cat CVS/Tag || basename $(cat CVS/Root 2>&- || echo "HEAD") ) CVSTAG=${CVSTAG:+ $C_$_gcl_colors[uptodate]$_C$CVSTAG} - fi - - if [ -d .svn ] - then - # get svn status - # - [ "$DEBUG" = "yes" ] && echo -n " SVN status..." - SVNREV=$(LC_ALL=C svn info 2>&- $PWD | awk '/^Revision: / {print $2}') - SVNREVSIZE=${#${SVNREV:+ r$SVNREV}} - if [ "$SVNREV" != "" ] - then - if [ ! -z "$CHECK_SVN_STATUS" ] - then - SVNSTATUS="$(svn diff 2>&-)" - SVNSTATUS=${${SVNSTATUS:+$_gcl_colors[changed]}:-$_gcl_colors[uptodate]} - fi - fi - SVNREV=${SVNREV:+$C_$_prompt_colors[doubledot]$_C $C_$SVNSTATUS$_C"r"$SVNREV} - [ "$DEBUG" = "yes" ] && echo - fi + fi + + if [ -d .svn ] + then + # get svn status + # + [ "$DEBUG" = "yes" ] && echo -n " SVN status..." + SVNREV=$(LC_ALL=C svn info 2>&- $PWD | awk '/^Revision: / {print $2}') + SVNREVSIZE=${#${SVNREV:+ r$SVNREV}} + if [ "$SVNREV" != "" ] + then + if [ ! -z "$CHECK_SVN_STATUS" ] + then + SVNSTATUS="$(svn diff 2>&-)" + SVNSTATUS=${${SVNSTATUS:+$_gcl_colors[changed]}:-$_gcl_colors[uptodate]} + fi + fi + SVNREV=${SVNREV:+$C_$_prompt_colors[doubledot]$_C $C_$SVNSTATUS$_C"r"$SVNREV} + [ "$DEBUG" = "yes" ] && echo + fi # get hg status [ "$DEBUG" = "yes" ] && echo -n " HG status..." @@ -271,9 +271,9 @@ __update_prompt_elements() CURDIR="$C_$_prompt_colors[path]$_C%`echo $spaceleft`<..<"$MY_PATH"%<<$C_$color[none]$_C" [ "$DEBUG" = "yes" ] && echo - VCSBRANCH=$CVSTAG$SVNREV$GITBRANCH$HGBRANCH + VCSBRANCH=$CVSTAG$SVNREV$GITBRANCH$HGBRANCH - __compilation 2>&- + __compilation 2>&- } __redefine_prompt () @@ -297,7 +297,7 @@ __two_lines_prompt () { ## 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... - # + # PS1=$HBAR$(print -Pn "\r" ; tput cuf 1)${AGENTS}$(tput cuf 1)${ERROR}$(tput cub $COLUMNS ; tput cuf $(($COLUMNS - $DATESIZE)))$C_$_prompt_colors[bar]$_C$DATE" "$C_$prompt_color[default]$_C$C_$_prompt_colors[user]$_C"%n"$C_$_prompt_colors[arob]$_C"@"$C_$_prompt_colors[host]$_C"%M"$C_$_prompt_colors[display]$_C"${DISPLAY:+($DISPLAY)} "$CURDIR$VCSBRANCH" "$C_$_prompt_colors[soft_generic]$_C${COMPILATION}$C_$_prompt_colors[dies]$_C"%#"$C_$_prompt_colors[cmd]$_C" " -- cgit v1.2.3 From 8ca053002b72e57f0e63a8e40144e39123a9280d Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Fri, 9 Mar 2012 11:44:13 +0100 Subject: [Prompt] spaceleft / Compilation --- 12_Prompts.zsh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/12_Prompts.zsh b/12_Prompts.zsh index 13ec48c..7ec76fd 100644 --- a/12_Prompts.zsh +++ b/12_Prompts.zsh @@ -189,6 +189,9 @@ __update_prompt_elements() ## Second line of prompt : don't let the path garbage the entire line ## + unset COMPILATION + __compilation 2>&- + # get cvs tag # CVSTAG="" @@ -238,7 +241,7 @@ __update_prompt_elements() PATHSIZE=${#PATHSIZE} [ "$DEBUG" = "yes" ] && echo [ "$DEBUG" = "yes" ] && echo -n " Resize path / gitbranch..." - spaceleft=`print -Pn "$SHLVL - %n@%m $ ls -laCdtrux $(__expand_text "$DATE")"` + spaceleft=`__expand_text "%n@%m${DISPLAY:+($DISPLAY)}$COMPILATION $ ls -laCdtrux $DATE"` spaceleft=$(($COLUMNS - ${#spaceleft})) #minimalpathsize=`print -Pn "../%1~"` #minimalpathsize=${#minimalpathsize} @@ -273,7 +276,6 @@ __update_prompt_elements() VCSBRANCH=$CVSTAG$SVNREV$GITBRANCH$HGBRANCH - __compilation 2>&- } __redefine_prompt () -- cgit v1.2.3 From 286edca6a2971be3852be898ff9297ea8f672ad0 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Fri, 9 Mar 2012 14:15:58 +0100 Subject: [Prompt] preexec : YAHAHAAAA ! --- 12_Prompts.zsh | 11 +++++++---- 13_ZshHighlight.zsh | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/12_Prompts.zsh b/12_Prompts.zsh index 7ec76fd..d96dd2e 100644 --- a/12_Prompts.zsh +++ b/12_Prompts.zsh @@ -57,8 +57,8 @@ chpwd() __expand_text() { - # strips the %{...%} and newlines characters - print -Pn -- "$(echo $@ | tr -d '\n' | sed 's/%{[^(%})]*%}//g;s/'$T_'//g;s/'$_T'//g')" + # strips the %{...%} and everything after \r characters + print -Pn -- "$(echo $@ | sed 's/\r.*//g;s/%{[^(%})]*%}//g;s/'$T_'//g;s/'$_T'//g')" } export _COLUMNS_OLD=0 @@ -87,11 +87,14 @@ preexec () __hbar __redefine_prompt - local lines="$(($( (__expand_text "$PROMPT";__expand_text "$1") | sed "s/\\(.\{0,$COLUMNS\}\\)/\\1\\n/g" | wc -l)))" + local lines + lines=$( (__expand_text "$PS1 $1" ) | sed "s/\\(.\{,$COLUMNS\}\\)/\\1\n/g" ) + lines=$( echo "$lines" | sed -n '/^$/n;p' | wc -l ) tput sc for i in {1..$lines} ; tput cuu1 - print -Pn "$PROMPT" + print -Pn "$PS1" tput rc + #print -Pn $C_"30"$_C"-$(echo -n "$1" | wc -l)-> ${(q)1} <-"$lines"-\n" print -Pn "$C_$_prompt_colors[exec]$_C" } diff --git a/13_ZshHighlight.zsh b/13_ZshHighlight.zsh index 3005220..93f8e01 100644 --- a/13_ZshHighlight.zsh +++ b/13_ZshHighlight.zsh @@ -11,9 +11,9 @@ then fi -ZSH_HIGHLIGHT_STYLES[default]="none" +ZSH_HIGHLIGHT_STYLES[default]="fg=cyan" -ZSH_HIGHLIGHT_STYLES[assign]="none" +ZSH_HIGHLIGHT_STYLES[assign]="fg=cyan" ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]="fg=yellow,bold" ZSH_HIGHLIGHT_STYLES[back-quoted-argument]="green" -- cgit v1.2.3