summaryrefslogtreecommitdiff
path: root/12_Prompts.zsh
diff options
context:
space:
mode:
authorHugues Hiegel <hugues@hiegel.fr>2012-03-09 15:22:49 +0100
committerHugues Hiegel <hugues@hiegel.fr>2012-03-09 15:22:49 +0100
commit05affb78ad7c4720f783f2f4d13e5780f8d2aa18 (patch)
treef7dd77379529d61f75fd2c05e6058f5f3bbda045 /12_Prompts.zsh
parentf61008d24c79c105c77682b2f7ce1c40b32744dc (diff)
parent286edca6a2971be3852be898ff9297ea8f672ad0 (diff)
Merge branch 'master' of git:zdotdir
Conflicts: 12_Prompts.zsh
Diffstat (limited to '12_Prompts.zsh')
-rw-r--r--12_Prompts.zsh152
1 files changed, 56 insertions, 96 deletions
diff --git a/12_Prompts.zsh b/12_Prompts.zsh
index f927813..d96dd2e 100644
--- a/12_Prompts.zsh
+++ b/12_Prompts.zsh
@@ -57,23 +57,24 @@ 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
__hbar()
{
- if [ $COLUMNS != $_COLUMNS_OLD ]
- then
- 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 ()
@@ -83,15 +84,17 @@ 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$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
+ 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 "$PS1"
+ tput rc
+ #print -Pn $C_"30"$_C"-$(echo -n "$1" | wc -l)-> ${(q)1} <-"$lines"-\n"
print -Pn "$C_$_prompt_colors[exec]$_C"
}
@@ -113,7 +116,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 +126,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 +148,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 +156,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 +164,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,65 +180,21 @@ __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
##
+ unset COMPILATION
+ __compilation 2>&-
+
# get cvs tag
#
CVSTAG=""
@@ -248,21 +205,24 @@ __update_prompt_elements()
CVSTAG=${CVSTAG:+ $C_$_gcl_colors[uptodate]$_C$CVSTAG}
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" != "" ]
+ if [ -d .svn ]
then
- if [ ! -z "$CHECK_SVN_STATUS" ]
+ # 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
- SVNSTATUS="$(svn diff 2>&-)"
- SVNSTATUS=${${SVNSTATUS:+$_gcl_colors[changed]}:-$_gcl_colors[uptodate]}
+ 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
- SVNREV=${SVNREV:+$C_$_prompt_colors[doubledot]$_C $C_$SVNSTATUS$_C"r"$SVNREV}
- [ "$DEBUG" = "yes" ] && echo
# get hg status
[ "$DEBUG" = "yes" ] && echo -n " HG status..."
@@ -284,7 +244,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}
@@ -317,7 +277,8 @@ __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
+
}
__redefine_prompt ()
@@ -339,10 +300,9 @@ __yeah_prompt ()
__two_lines_prompt ()
{
- __cmd_exists __compilation && __compilation
## 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" "
@@ -378,7 +338,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