aboutsummaryrefslogtreecommitdiffhomepage
path: root/X11/eww/scripts/sys_info
diff options
context:
space:
mode:
Diffstat (limited to 'X11/eww/scripts/sys_info')
-rwxr-xr-xX11/eww/scripts/sys_info78
1 files changed, 78 insertions, 0 deletions
diff --git a/X11/eww/scripts/sys_info b/X11/eww/scripts/sys_info
new file mode 100755
index 0000000..a168be3
--- /dev/null
+++ b/X11/eww/scripts/sys_info
@@ -0,0 +1,78 @@
1#!/bin/bash
2
3## Files and Data
4PREV_TOTAL=0
5PREV_IDLE=0
6cpuFile="/tmp/.cpu_usage"
7
8## Get CPU usage
9get_cpu() {
10 if [[ -f "${cpuFile}" ]]; then
11 fileCont=$(cat "${cpuFile}")
12 PREV_TOTAL=$(echo "${fileCont}" | head -n 1)
13 PREV_IDLE=$(echo "${fileCont}" | tail -n 1)
14 fi
15
16 CPU=(`cat /proc/stat | grep '^cpu '`) # Get the total CPU statistics.
17 unset CPU[0] # Discard the "cpu" prefix.
18 IDLE=${CPU[4]} # Get the idle CPU time.
19
20 # Calculate the total CPU time.
21 TOTAL=0
22
23 for VALUE in "${CPU[@]:0:4}"; do
24 let "TOTAL=$TOTAL+$VALUE"
25 done
26
27 if [[ "${PREV_TOTAL}" != "" ]] && [[ "${PREV_IDLE}" != "" ]]; then
28 # Calculate the CPU usage since we last checked.
29 let "DIFF_IDLE=$IDLE-$PREV_IDLE"
30 let "DIFF_TOTAL=$TOTAL-$PREV_TOTAL"
31 let "DIFF_USAGE=(1000*($DIFF_TOTAL-$DIFF_IDLE)/$DIFF_TOTAL+5)/10"
32 echo "${DIFF_USAGE}"
33 else
34 echo "?"
35 fi
36
37 # Remember the total and idle CPU times for the next check.
38 echo "${TOTAL}" > "${cpuFile}"
39 echo "${IDLE}" >> "${cpuFile}"
40}
41
42## Get Used memory
43get_mem() {
44 printf "%.0f\n" $(free -m | grep Mem | awk '{print ($3/$2)*100}')
45}
46
47## Get Brightness
48get_blight() {
49 CARD=`ls /sys/class/backlight | head -n 1`
50
51 if [[ "$CARD" == *"intel_"* ]]; then
52 BNESS=`xbacklight -get`
53 LIGHT=${BNESS%.*}
54 else
55 BNESS=`blight -d $CARD get brightness`
56 PERC="$(($BNESS*100/255))"
57 LIGHT=${PERC%.*}
58 fi
59
60 echo "$LIGHT"
61}
62
63## Get Battery
64get_battery() {
65 BAT=CMB0
66 cat /sys/class/power_supply/${BAT}/capacity
67}
68
69## Execute accordingly
70if [[ "$1" == "--cpu" ]]; then
71 get_cpu
72elif [[ "$1" == "--mem" ]]; then
73 get_mem
74elif [[ "$1" == "--blight" ]]; then
75 get_blight
76elif [[ "$1" == "--bat" ]]; then
77 get_battery
78fi