summaryrefslogtreecommitdiff
path: root/qubes-dwm-6.2/scripts/dwm_status
blob: 9d806f0fa3b554f37f4132b0aafe9999c5a82d6e (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash

status_time() {
    date '+%d/%Hh%M'
}

status_bat() {
    local report=$(acpi | tr -d ',')
    echo $report | grep -qv Unknown
    if [ "$?" = "0" ]; then
        local status=$(echo $report | cut -d\  -f 3 | cut -b 1)
        local perc=$(echo $report | cut -d\  -f 4)
        local time=$(echo $report | cut -d\  -f 5 | sed 's/\([0-9]*\):\([0-9]*\).*/\1h\2m/')
        local output="$status$perc"
        if [ -n "$time" ]; then
            output="$output"" $time"
        fi;
        echo "$output"
    else
        echo ?
    fi
}

status_load() {
    local load=$(uptime)
    load=${load/#*load average: }
    load=${load%,*,*}
    echo "Load: $load"
}

status_temp() {
    local temp=$(( $(cat /sys/class/thermal/thermal_zone0/temp) / 1000 ))
    if [ "$temp" -gt "60" ]; then
        echo "$temp C | "
    else
        echo
    fi
}

status_autolock() {
    cat ~/.autolock_status
}

status_ram() {
    xl info | awk '/free_memory/ { printf("%.2fG free", $3/1024) } '
}

status_qubes() {
    local qubes=$(qvm-ls --no-spinner --raw-data --fields FLAGS 2>/dev/null | grep -v '^0' | grep '^.r......' | wc -l)
    echo "$qubes Qubes"
}

status_disk() {
    local disk=''
    local free=''
    local size=''
    local usage=''
    read size usage <<< $(qvm-pool -i $(qubes-prefs default-pool) | grep 'size\|usage' | sort | awk '{print $2}')
    free=$(($size - $usage))
    case ${#free} in
        1[3-5])
            disk="$(($free / 1099511627776))T" ;;
        1[0-2])
            disk="$(($free / 1073741824))G" ;;
        [7-9])
            disk="$(($free / 1048576))M" ;;
        [4-6])
            disk="$(($free / 1024))K" ;;
        [1-3])
            disk="$free Bytes" ;;
        *)
            disk="Error" ;;
    esac
    echo "$disk"
}

main() {
    local n
    for ((n=0; ; ++n)); do
        if (( n % 2 == 0 )); then
            #local load=$(status_load)
            local bat=$(status_bat)
            local time=$(status_time)
        fi
        # local ram=$(status_ram)
        # local disk=$(status_disk)
        local temp=$(status_temp)
        local qubes=$(status_qubes)
        local autolock=$(status_autolock)
        local status="$autolock$qubes | $temp$bat | $time"
        xsetroot -name "$status"
        sleep 30
    done
}

main