Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
working on a script asked by @kuraku on [arch forums](https://bbs.archlinux.org/viewtopic.php?pid=1213820#p1213820)
#!/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
@c00kiemon5ter

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.