add the functions needed for some keybindings
[zsh.git] / .zsh / functions / periodic
1 # -*- mode:sh -*-
2
3 # I use this function to generate a few variables which then get used in my prompt.
4 # This function here is only executed every X seconds, the prompt uses the variables set by it.
5 # This way I can include some information in my prompt which may need more time to collect
6 # than you want a promptdisplay to use
7 #
8 # The function has to fill in the associative array "ACPIDISPLAY", setting the following values
9 # (if available):
10 #
11 # bat1 - first battery
12 # bat2 - possible second battery, unset if none
13 # tz1 .. tzX - temperatures
14 # cpu - CPU frequency
15 # tznum - number of tempX entries
16 # ac - online or offline
17 case $LAPTOP in
18 yacpi)
19 ACPIDATA=(${(s:|:)"$(yacpi -p)"})
20
21 ACPIDISPLAY=(
22 bat1 ${${ACPIDATA[1]}[(w)3]}
23 bat2 ${${ACPIDATA[2]}[(w)3]}
24 ac ${${ACPIDATA[3]}[(w)3]}
25 tz5 ${${ACPIDATA[4]}[(w)3]}
26 tz4 ${${ACPIDATA[5]}[(w)3]}
27 tz3 ${${ACPIDATA[6]}[(w)3]}
28 tz2 ${${ACPIDATA[7]}[(w)3]}
29 tz1 ${${ACPIDATA[8]}[(w)3]}
30 tz0 ${${ACPIDATA[9]}[(w)3]}
31 cpu ${${${ACPIDATA[11]}[(w)3]}//\/*/}
32 tznum 5
33 )
34 PR_APM_BAT='${PR_YELLOW}B: ${PR_RED}$ACPIDISPLAY[bat1] ${(e)PR_SLASH}${ACPIDISPLAY[bat2]} ${PR_YELLOW}%%'
35 PR_APM_TEMP='T: ${PR_RED}$ACPIDISPLAY[tz0]${(e)PR_SLASH}$ACPIDISPLAY[tz1]${(e)PR_SLASH}$ACPIDISPLAY[tz2]${(e)PR_SLASH}$ACPIDISPLAY[tz3]${(e)PR_SLASH}$ACPIDISPLAY[tz4]${(e)PR_SLASH}$ACPIDISPLAY[tz5]${PR_YELLOW}°C'
36 PR_APM_CPU='CPU: ${PR_RED}$ACPIDISPLAY[cpu]${PR_YELLOW}MHz'
37 PR_APM_AC='AC: ${PR_RED}$ACPIDISPLAY[ac]'
38 PR_APM_LAST='${PR_CYAN}'
39
40 case $TOOLONG in
41 0)
42 PR_APM="${PR_APM_BAT} ${PR_APM_TEMP} ${PR_APM_CPU} ${PR_APM_AC}${PR_APM_LAST}"
43 ;;
44 1)
45 PR_APM="${PR_APM_BAT} ${PR_APM_TEMP} ${PR_APM_CPU} ${PR_APM_LAST}"
46 ;;
47 2)
48 PR_APM="${PR_APM_BAT} ${PR_APM_TEMP} ${PR_APM_LAST}"
49 ;;
50 3)
51 PR_APM="${PR_APM_BAT} ${PR_APM_LAST}"
52 ;;
53 4)
54 PR_APM=""
55 ;;
56 *)
57 PR_APM=""
58 ;;
59 esac
60 ;;
61 ibam)
62 ACPIDATA=$(ibam --percentbattery)
63 ACPIDISPLAY=(
64 bat1 ${${ACPIDATA[(f)1]}[(w)-2]}
65 tznum 0
66 )
67 PR_APM='${PR_RED}B: $ACPIDISPLAY[bat1] ${PR_CYAN}'
68
69 ;;
70 *)
71 unset ACPIDATA
72 unset ACPIDISPLAY
73 PR_APM=''
74 esac
75
76 # Finally see how long the acpi related prompt is
77 PR_APM_TEMP=${PR_APM//\${\(e\)PR_SLASH}/#}
78 PR_APM_LENGTH=${(e)PR_APM_TEMP//\${PR_(LIGHT|)(RED|GREEN|YELLOW|BLUE|MAGENTA|CYAN|WHITE)}/}