public
Last active

working on a script asked by @kuraku on [arch forums](https://bbs.archlinux.org/viewtopic.php?pid=1213820#p1213820)

  • Download Gist
sys_monitor
Shell
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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
#!/usr/bin/env bash
 
# Status script
# original: https://bitbucket.org/jasonwryan/eeepc/src/fefeccd4b280/Scripts/dwm-status
# colours: 01:normal 02:green 03:orange 04:red 05:gray 06:blue
 
## sleep interval - delay between updates
declare -r interval=3
 
## color definitions
if [[ "$1" == 'dwm' ]]
then # use dwm status color codes
declare -r -A colors=(
[normal]="\x01"
[green]="\x02"
[orange]="\x03"
[red]="\x04"
[gray]="\x05"
[blue]="\x06"
)
else # use bar status colors codes
declare -r -A colors=(
[normal]="\f1"
[green]="\f2"
[orange]="\f3"
[red]="\f4"
[gray]="\f5"
[blue]="\f6"
)
fi
 
keyboard_indicator() {
awk -vn="${colors[normal]}" -vg="${colors[green]}" '
BEGIN { l = n"??" }
$1 == "layout:" { l = $2; exit }
END { printf(" %s%s%s", g, l, n) }' < <(setxkbmap -query)
}
 
# FIXME .. no battery here - no acpi command ..
#battery_status() {
# ac="$(awk '{ gsub(/%|%,/, "");} NR==1 {print $4}' <(acpi -V))"
# on="$(grep "on-line" <(acpi -V))"
# if [ -z "$on" ] && [ "$ac" -gt "15" ]; then
# echo -e "\uE04F \x02$ac%\x05 |\x01"
# elif [ -z "$on" ] && [ "$ac" -le "15" ]; then
# echo -e "\uE04F \x05n/a\x05 |\x01"
# else
# echo -e "\uE023 \x02$ac%\x05 |\x01"
# fi
#}
 
free_mem() {
awk -vn="\\${colors[normal]}" -vg="\\${colors[green]}" -vb="\\${colors[blue]}" '
$1 == "-/+" { if($3 > $4) c = g; else c = b; exit }
END { printf(" %s%s%s MB%s", c, $3, b, n) }' < <(free -m)
}
 
cpu_usage() {
read _ a1 b1 c1 idle1 _ < /proc/stat
sleep 0.5
read _ a2 b2 c2 idle2 _ < /proc/stat
 
if ((
total1 = a1 + b1 + c1 + idle1,
total2 = a2 + b2 + c2 + idle2,
tdiff = total2 - total1,
cpu_usage = 100 * (tdiff - (idle2 - idle1)) / tdiff,
cpu_usage > 50
))
then printf '%b %s%s%%%s' "\uE031" "${colors[blue]}" "$cpu_usage" "${colors[normal]}"
else printf '%b %s%s%%%s' "\uE031" "${colors[normal]}" "$cpu_usage" "${colors[normal]}"
fi
}
 
cpu_speed() {
awk -vn="\\${colors[normal]}" -vg="\\${colors[gray]}" '
$1$2 == "cpuMHz" { printf("%s%s%s ", n, $4, n) }' /proc/cpuinfo
}
 
hdd_space() {
awk -vn="\\${colors[normal]}" '
index($1, "/dev/") { s = s$5" " }
END{ printf(" %s%s", s, n) }' < <(df -P | sort -d)
}
 
net_speed () {
awk -vn="\\${colors[normal]}" -vb="\\${colors[blue]}" -vg="\\${colors[green]}" '
$1$2 == "RXpackets" { rx = $5 } $1$2 == "TXpackets" { tx = $5 }
END { printf(" %s%s%s  %s%s%s", g, rx, n, b, tx, n) }' < <(ifconfig eth0)
}
 
time_and_date() {
date "+ ${colors[red]}%H:%M %d%m%Y${colors[normal]}"
}
 
temperature() {
awk -vn="\\${colors[normal]}" -vg="\\${colors[green]}" '
$1 == "temp1:" { cpu = $2 }
$1 == "temp2:" { mb = $2 }
END { printf(" %s%s %s%s", g, cpu, mb, n) }' < <(sensors)
}
 
sep() {
printf '%s | %s' "${colors[gray]}" "${colors[normal]}"
}
 
## ommited: battery_status keyboard_indicator
output() {
net_speed
sep
cpu_usage
sep
cpu_speed
sep
temperature
sep
free_mem
sep
hdd_space
sep
time_and_date
}
 
# run this thing :)
while true
do
if [[ "$1" == 'dwm' ]]
then xsetroot -name "$(output)"
else printf '%s%s%s\n' "\r\fr\br\ur" "$(output)" "\fr\br\ur"
fi
sleep "$interval"
done

need to find the equivalent of shell's printf '%b\n' "\uXXXX" for awk

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.