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