home
/
code
/
khome.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
22f1641
)
Support optional label in bar gauge
author
Siraaj Khandkar
<siraaj@khandkar.net>
Sun, 1 Nov 2020 19:03:59 +0000
(14:03 -0500)
committer
Siraaj Khandkar
<siraaj@khandkar.net>
Sun, 1 Nov 2020 19:03:59 +0000
(14:03 -0500)
home/lib/login_functions.sh
patch
|
blob
|
blame
|
history
diff --git
a/home/lib/login_functions.sh
b/home/lib/login_functions.sh
index
0069028
..
a497cbc
100644
(file)
--- a/
home/lib/login_functions.sh
+++ b/
home/lib/login_functions.sh
@@
-373,12
+373,13
@@
bar_gauge() {
awk -v width="$width" '
{
awk -v width="$width" '
{
- used = $1
- total = $2
+ cur = $1
+ max = $2
+ lab = $3
- u = num_scale(
used, total
, 1, width)
+ u = num_scale(
cur, max
, 1, width)
- printf "
[
"
+ printf "
%s%s[", lab, lab ? " " : "
"
for (i=1; i<=width; i++) {
c = i <= u ? "|" : "-"
printf "%s", c
for (i=1; i<=width; i++) {
c = i <= u ? "|" : "-"
printf "%s", c
@@
-392,30
+393,9
@@
bar_gauge() {
'
}
'
}
-motd_mem() {
- local -r bar_width="$1"
-
- printf 'mem '
- free \
- | awk '$1 == "Mem:" {total=$2; used=$3; print used, total}' \
- | bar_gauge "$bar_width"
-}
-
-motd_disk() {
- local -r bar_width="$1"
-
- printf 'disk '
- df ~ \
- | awk 'NR == 2 {used=$3; avail=$4; total=used+avail; print used, total}' \
- | bar_gauge "$bar_width"
-}
-
motd_batt() {
motd_batt() {
- local -r bar_width="$1"
-
case "$(uname)" in
'Linux')
case "$(uname)" in
'Linux')
- printf 'batt '
upower --dump \
| awk '
/^Device:[ \t]+/ {
upower --dump \
| awk '
/^Device:[ \t]+/ {
@@
-436,11
+416,10
@@
motd_batt() {
/^$/ {
if (device["is_battery"] && device["path"] == "/org/freedesktop/UPower/devices/DisplayDevice")
/^$/ {
if (device["is_battery"] && device["path"] == "/org/freedesktop/UPower/devices/DisplayDevice")
- print device["battery_percentage"], 100
+ print device["battery_percentage"], 100
, "batt"
delete device
}
delete device
}
- ' \
- | bar_gauge "$bar_width"
+ '
;;
esac
}
;;
esac
}
@@
-465,10
+444,11
@@
motd() {
echo 'Resources'
(
echo 'Resources'
(
- motd_mem "$bar_width"
- motd_disk "$bar_width"
- motd_batt
"$bar_width"
+ free | awk '$1 == "Mem:" {print $3, $2, "mem"}'
+ df ~ | awk 'NR == 2 {print $3, $3 + $4, "disk"}'
+ motd_batt
) \
) \
+ | bar_gauge "$bar_width" \
| column -t \
| indent "$indent_unit"
| column -t \
| indent "$indent_unit"
@@
-518,8
+498,8
@@
motd() {
| column -t \
| indent "${indent_unit}${indent_unit}"
| column -t \
| indent "${indent_unit}${indent_unit}"
- echo "${indent_unit}servers:"
# WARN: ensure: $USER ALL=(ALL) NOPASSWD:/bin/netstat
# WARN: ensure: $USER ALL=(ALL) NOPASSWD:/bin/netstat
+ echo "${indent_unit}TCP servers"
sudo -n netstat -tlnp \
| awk 'NR > 2 {print $7}' \
| awk -F/ '{print $2}' \
sudo -n netstat -tlnp \
| awk 'NR > 2 {print $7}' \
| awk -F/ '{print $2}' \
This page took
0.041098 seconds
and
4
git commands to generate.