aboutsummaryrefslogtreecommitdiffstats
path: root/termbar.example
blob: 27015c81744b7dc3a27fcd0a787aa5e9ed80ee2f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh

## Debug
# set -x

# These will keep termbar running, but at the cost of leaving processes open
# when X dies. Helpful to use when tweaking
#trap 'exec $0' HUP # Restart itself
#trap 'tput cnorm; exit 1' INT QUIT TERM

clock() {
    CLOCK=$(date '+%a %d %b %H:%M:%S')
}

workspace_id() {
    WORKSPACE_ID=$(xprop -root 32c '\t$0' _NET_CURRENT_DESKTOP | cut -f 2)
}

convert_to_hours() {
    h=$((${1}/60))
    m=$((${1}%60))

    printf "%02d:%02d" $h $m
}
bat() {
    BAT_PCT=$(apm -l)
    BAT_TIME=$(convert_to_hours $(apm -m))
    # ↯ ⋇

    if [ $(sysctl hw.sensors.acpiac0.indicator0 | grep -c On) -eq "1" ]; then
        AC_STATUS=PWR
    else
        AC_STATUS=BAT
    fi

}

mem() {
    MEM=$(top -n | grep Memory | awk {'print $3'})
}

cpu() {
    _CPU_SPEED=$(sysctl hw.cpuspeed | cut -d "=" -f 2)
    CPU_SPEED=$(bc -l -e scale=1 -e ${_CPU_SPEED}/1000 -e quit | awk '{printf "%.1f", $0}')
    CPU_TEMP=$(sysctl hw.sensors.cpu0.temp0 | cut -d "=" -f 2 | cut -d "." -f 1)
}

vol() {
    _VOL=$(sndioctl output.level | cut -d "=" -f 2)
    VOL=$(bc -l -e scale=1 -e ${_VOL}*100 -e quit | awk '{printf "%.1f\n", $0}')
}

while true; do
    clock
    workspace_id
    bat
    cpu
    mem
    vol

    # Overwrites the input
    clear
    #tput cup 1 0  # tput sometimes leaves trailing numbers
    printf "[${WORKSPACE_ID}] %132.110s CPU: ${CPU_SPEED}Ghz ${CPU_TEMP}C | MEM: ${MEM} | ${AC_STATUS} ${BAT_PCT}%% (${BAT_TIME}) | VOL: ${VOL}%% | ${CLOCK}"

    sleep 5
done