initial
[zsh.git] / .zsh / functions / precmd
1 # -*- mode:sh -*-
2
3 # update VCS information
4 vcs_info
5
6 # set variable debian_chroot if running in a chroot with /etc/debian_chroot
7 if [[ -z "$debian_chroot" ]] && [[ -r /etc/debian_chroot ]] ; then
8 debian_chroot="chroot: $(cat /etc/debian_chroot)"
9 fi
10 ###
11
12 local TERMWIDTH
13 (( TERMWIDTH = ${COLUMNS} - 1 ))
14
15 # Truncate the path if it's too long.
16 PR_FILLBAR=""
17 PR_PWDLEN=""
18
19 local promptsize=${#${(%):---(%n@%m:%l)---()--}}
20 local pwdsize=${#${(%):-%~}}
21 # for whatever reason this works better if set to 3 on systems where no acpi info is in prompt
22 local apmsize=3
23
24 # Finally see how long the acpi related prompt is
25 PR_APM_TEMP=${PR_APM//\${\(e\)PR_SLASH}/#}
26 PR_APM_LENGTH=${(e)PR_APM_TEMP//\${PR_(LIGHT|)(RED|GREEN|YELLOW|BLUE|MAGENTA|CYAN|WHITE)}/}
27
28 # The info i collect for my laptop is - well. long. As I usually have my terms in full screen
29 # mode that doesnt matter, there is enough space. But for some cases I may want smaller
30 # windows, so deal with it and make the acpi line smaller by dropping parts of it.
31
32 (( apmsize=${(e)#PR_APM_LENGTH} - 2 ))
33
34 while [[ "$promptsize + $pwdsize + $apmsize" -gt $TERMWIDTH ]]; do
35 (( TOOLONG=$TOOLONG + 1 ))
36
37 if [[ "$TOOLONG" -gt 5 ]]; then
38 break
39 fi
40 periodic
41 (( apmsize=${(e)#PR_APM_LENGTH} - 2 ))
42 done
43
44 if [[ ${(e)#PR_APM_LENGTH} -gt 10 ]]; then
45 (( apmsize=${(e)#PR_APM_LENGTH} - 2 ))
46 else
47 apmsize=3
48 fi
49
50 if [[ "$promptsize + $pwdsize + $apmsize" -gt $TERMWIDTH ]]; then
51 ((PR_PWDLEN=$TERMWIDTH - $promptsize - $apmsize ))
52 else
53 PR_FILLBAR="\${(l.(($TERMWIDTH - ($promptsize + $pwdsize + $apmsize)))..${PR_HBAR}.)}"
54 fi
55
56 if [[ "$PR_BARLENGTH" -lt "${#${(e)PR_FILLBAR}}" ]]; then
57 (( TOOLONG=$TOOLONG - 1 ))
58 if [[ "$TOOLONG" -lt 0 ]]; then
59 TOOLONG=0
60 fi
61 fi
62 PR_BARLENGTH=${#${(e)PR_FILLBAR}}