# load prompt functions setopt promptsubst unsetopt transient_rprompt # leave the pwd # get the colors source ~/.zcolors # signal names ZSIG=$(kill -l) # set the prompt set_prompt() { mypath="$C_OFF$C_L_GREEN%~" myjobs=() for a (${(k)jobstates}) {j=$jobstates[$a];i="${${(@s,:,)j}[2]}" myjobs+=($a${i//[^+-]/})} myjobs=${(j:,:)myjobs} ((MAXMID=$COLUMNS / 2)) # truncate to this value #psvar=( $history[$[${(%):-%h}-1]] ) RPS1="$RPSL$C_L_GREEN%$MAXMID<...<$mypath$RPSR" rehash } # faster than seperate script bat() { dc=$(cat /proc/acpi/battery/BAT0/info | grep 'last full' | awk ' { print $4 }') rc=$(cat /proc/acpi/battery/BAT0/state | grep 'remaining' | awk ' { print $3 } ') p=$(echo 3k $rc $dc / 100 \* p | dc ) if grep -q discharging /proc/acpi/battery/BAT0/state; then printf "%02d" "$p" else printf "%02d+" "$p" fi } # print optional number of bg jobs (when 0 show nothing) # when the path is too long only the last section is shown # root is simple and all red # print @-sign before the hostname if we got into this host via SSH if [ -z $SSH_TTY ]; then ZSSH= else ZSSH='@ ' fi # reset the colors when printing the rside prompt always if [ "$USER" = "root" ]; then PS1=$'$C_RED%~ %#% $C_OFF ' else ZU=${USER[1]} PS1=$'$C_BLUE%(1j.$myjobs% $C_OFF .$C_OFF)%B$ZSSH%b%m.%B$ZU%b$C_OFF$C_L_GREEN%#$C_OFF ' fi RPSL=$'$C_OFF' if [ $HOST = "charm" ]; then RPSR=$'$C_OFF$C_RED%(0?.$C_OFF. $E) $C_GREY$(bat)$C_OFF' else RPSR=$'$C_OFF$C_RED%(0?.$C_OFF. $E)$C_OFF' fi RPS2='%^' precmd() { # add the name of the signal if its there # must be done here in this function... EX=`print -P %?` # EX=$(print -P %?) # does not work... if [[ $EX -ge 128 ]]; then ((k=$EX-128)) E="-${${(s: :)ZSIG}[$k]}" else E=$EX fi set_prompt }