STATUS_DIR=$HOME/var/run/status
STATUS_FILE__WIFI=$STATUS_DIR/wifi
STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF=$STATUS_DIR/notified_energy_bellow_half
+DISK_IO_DEVICE='dm-1'
+DISK_SPACE_DEVICE='/dev/mapper/kubuntu--vg-root'
+
load=$(awk '{printf("%4.2f", $1)}' /proc/loadavg)
fan=$(awk '/^speed:/ {printf "%4d", $2}' /proc/acpi/ibm/fan)
-cpu=$($BIN/khatus_cpu_usage_from_proc_since_last_check)
+#cpu=$($BIN/khatus_cpu_usage_from_proc_since_last_check)
memory=$(
free \
total=$2;
used=$3;
cache=$6;
- prev_file = "/home/siraaj/var/run/status/memory_used_percentage";
+ prev_file = ENVIRON["HOME"] "/var/run/status/memory_used_percentage";
curr = round(used / total * 100);
getline prev < prev_file;
print curr > prev_file;
curr_sectors_read = $3
curr_sectors_write = $7
- prev_file_prefix = "/home/siraaj/var/run/status/disk_io"
+ prev_file_prefix = ENVIRON["HOME"] "/var/run/status/disk_io"
prev_sectors_read_file = prev_file_prefix "_sectors_read"
prev_sectors_write_file = prev_file_prefix "_sectors_write"
printf("%0.3f▲ %0.3f▼\n", diff_write, diff_read);
}
- ' /sys/block/dm-1/stat
+ ' "/sys/block/$DISK_IO_DEVICE/stat"
)
disk=$(
df \
- | awk -v disk_io="$disk_io" '
+ | awk \
+ -v disk_io="$disk_io" \
+ -v device="$DISK_SPACE_DEVICE" \
+ '
function round(n) {return int(n + 0.5)}
- $1 == "/dev/mapper/kubuntu--vg-root" {
+ $1 == device {
curr_perc = $5; sub("%$", "", curr_perc);
- prev_perc_file = "/home/siraaj/var/run/status/disk_space_used";
+ prev_perc_file = ENVIRON["HOME"] "/var/run/status/disk_space_used";
getline prev_perc < prev_perc_file;
print curr_perc > prev_perc_file;
if (curr_perc > prev_perc) {
printf("%s[%d%% %s]", direction, curr_perc, disk_io);
}')
+# TODO: Wi-Fi status file should be a file per-wifi-device
network=$(
ip -s addr \
- | awk -v wifi_conn=$(cat $STATUS_FILE__WIFI) '
+ | awk \
+ -v wifi_conn="$(cat $STATUS_FILE__WIFI)" \
+ -v prefixes_of_interfaces_to_show='w' \
+ '
BEGIN {
bytes_per_unit = 1024 * 1024
}
}
END {
- for (i=1; i<=sequence; i++) {
- interface = interfaces[i]
+ for (seq=1; seq<=sequence; seq++) {
+ interface = interfaces[seq]
+ label = substr(interface, 1, 1)
if (addrs[interface]) {
curr_read = io[interface, "r"]
curr_write = io[interface, "w"]
- prefix = "/home/siraaj/var/run/status/io_net_" interface
+ prefix = ENVIRON["HOME"] "/var/run/status/io_net_" interface
prev_read_file = prefix "_read"
prev_write_file = prefix "_write"
print curr_write > prev_write_file
io_stat = sprintf("%0.3f▲ %0.3f▼", diff_written, diff_read)
+ if (interface ~ "^w") {
+ label = label ":" wifi_conn
+ }
} else {
io_stat = "--"
}
-
- label = substr(interface, 1, 1)
- if (interface == "wlp3s0") {
- label = label ":" wifi_conn
- }
-
- if (i == sequence) {
- sep = ""
- } else {
- sep = " | "
+ number_of_interfaces_to_show = \
+ split(\
+ prefixes_of_interfaces_to_show,\
+ array_of_prefixes_of_interfaces_to_show,\
+ " +"\
+ )
+ for (n = 1; n <= number_of_interfaces_to_show; n++) {
+ prefix = array_of_prefixes_of_interfaces_to_show[n]
+ if (interface ~ ("^" prefix)) {
+ if (++count_printed > 1) {
+ sep = " "
+ } else {
+ sep = ""
+ }
+ printf("%s%s:%s", sep, label, io_stat)
+ }
}
-
- printf("%s:%s%s", label, io_stat, sep)
}
}'
)
printf("%s%s", direction_of_change, percentage)
}')
-datetime=$(date +'%a, %b %d, %H:%M:%S')
+datetime=$(date +'%a %b %d %H:%M:%S')
+#datetime=$(
+# date +'%a %u %b %d %H:%M:%S' \
+# | awk '
+# {
+# wday_name = $1
+# wday_seq = $2
+# month = $3
+# mday = $4
+# time = $5
+#
+# week = ""
+# for (i=1; i<=7; i++) {
+# if (i == 6 || i == 4) {
+# sep = " "
+# } else {
+# sep = ""
+# }
+#
+# if (i == wday_seq) {
+# #symbol = substr(wday_name, 1, 1)
+# symbol = "/"
+# } else if (i < wday_seq){
+# symbol = "X"
+# } else {
+# symbol = "_"
+# }
+# week = week sep symbol
+# }
+#
+# print "["week"]", month, mday, time;
+# }
+# '
+#)
#volume_amixer=$(
# amixer get Master \
'
)
-volume="[$volume_pactl]"
+volume="($volume_pactl)"
screen_brightness=$(
max=$(cat /sys/class/backlight/acpi_video0/max_brightness)
rm -f "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF"
fi
-weather=$(awk 'NR == 1 {printf("%d°F", $1)}' ~/var/run/metar-KJFK-decoded-temp-fahrenheit)
-
-signal_last_msg_age=$(
- ls -lt --time-style=+%s $HOME/var/lib/signal/latest_message.json \
- | awk -v now_seconds=$(date +%s) \
- '{
- mtime_seconds = $6;
- seconds = now_seconds - mtime_seconds;
- minutes = seconds / 60;
- hours = minutes / 60;
- days = hours / 24;
- weeks = days / 7;
- months = days / 30;
- #fmt = "%.1f";
- fmt = "%d";
- printf(fmt " s\n", seconds);
- printf(fmt " m\n", minutes);
- printf(fmt " h\n", hours);
- printf(fmt " d\n", days);
- printf(fmt " w\n", weeks);
- printf(fmt " mo\n", months);
- }' \
- | awk '$1 >= 1' \
- | sort -n -k 1 \
- | head -1 \
- | tr -d ' '
-)
-
-mpd_state=$(
- echo 'status' \
- | nc 127.0.0.1 6600 \
- | awk '
- {
- status[$1] = $2
- }
-
- END {
- state = status["state:"]
- symbol = "-"
- if (state == "play") {
- symbol = "▶"
- } else if (state == "pause") {
- symbol = "❚❚"
- } else if (state == "stop") {
- symbol = "⬛"
- }
- printf("%s", symbol)
- }
- '
-)
+weather=$(awk 'NR == 1 {printf("%s°F", $1)}' ~/var/run/metar-KJFK-decoded-temp-fahrenheit)
+
+#signal_last_msg_age=$(
+# ls -lt --time-style=+%s $HOME/var/lib/signal/latest_message.json \
+# | awk -v now_seconds=$(date +%s) \
+# '{
+# mtime_seconds = $6;
+# seconds = now_seconds - mtime_seconds;
+# minutes = seconds / 60;
+# hours = minutes / 60;
+# days = hours / 24;
+# weeks = days / 7;
+# months = days / 30;
+# #fmt = "%.1f";
+# fmt = "%d";
+# printf(fmt " s\n", seconds);
+# printf(fmt " m\n", minutes);
+# printf(fmt " h\n", hours);
+# printf(fmt " d\n", days);
+# printf(fmt " w\n", weeks);
+# printf(fmt " mo\n", months);
+# }' \
+# | awk '$1 >= 1' \
+# | sort -n -k 1 \
+# | head -1 \
+# | tr -d ' '
+#)
-mpd_current=$(
+mpd_currentsong=$(
echo 'currentsong' \
| nc 127.0.0.1 6600 \
| awk -v max_chars=10 '
}
END {
- if (data["Name:"]) {
- out = data["Name:"]
- } else {
- file = data["file:"]
+ name = data["Name:"]
+ title = data["Title:"]
+ file = data["file:"]
+
+ if (name) {
+ out = name
+ } else if (title) {
+ out = title
+ } else if (file) {
last = split(file, parts, "/")
out = parts[last]
+ } else {
+ out = ""
}
+
printf("%s", substr(out, 1, max_chars))
}
'
)
-graphics_card=$(
- nvidia-smi \
- --format=csv,noheader,nounits \
- --query-gpu=memory.total,memory.used,temperature.gpu \
- | awk -F ',' '
+mpd_state=$(
+ echo 'status' \
+ | nc 127.0.0.1 6600 \
+ | awk \
+ -v current_song="$mpd_currentsong" \
+ '
{
- mem_total = $1;
- mem_used = $2;
- temp = $3;
- mem_used_percent = (100 * mem_used) / mem_total;
- printf("[%d%% %dC]", mem_used_percent, temp);
+ status[$1] = $2
+ }
+
+ /^time: +[0-9]+:[0-9]+$/ {
+ split($2, time, ":")
+ seconds_current = time[1]
+ seconds_total = time[2]
+
+ hours = int(seconds_current / 60 / 60);
+ secs_beyond_hours = seconds_current - (hours * 60 * 60);
+ mins = int(secs_beyond_hours / 60);
+ secs = secs_beyond_hours - (mins * 60);
+ if (hours > 0) {
+ current_time = sprintf("%d:%.2d:%.2d", hours, mins, secs)
+ } else {
+ current_time = sprintf("%.2d:%.2d", mins, secs)
+ }
+
+ if (seconds_total > 0) {
+ time_percentage = (seconds_current / seconds_total) * 100
+ current_percentage = sprintf("%d%%", time_percentage)
+ } else {
+ current_percentage = "~"
+ }
+ }
+
+ function print_known_state(symbol) {
+ printf(\
+ "%s %s %s %s",
+ symbol, current_time, current_percentage, current_song \
+ )
+ }
+
+ function print_unknown_state(symbol) {
+ printf("%s", symbol)
+ }
+
+ END {
+ state = status["state:"]
+
+ if (state == "play") {
+ print_known_state("▶")
+ } else if (state == "pause") {
+ print_known_state("❚❚")
+ } else if (state == "stop") {
+ print_known_state("⬛")
+ } else {
+ print_unknown_state("--")
+ }
}
'
)
+#graphics_card=$(
+ #nvidia-smi \
+ #--format=csv,noheader,nounits \
+ #--query-gpu=memory.total,memory.used,temperature.gpu \
+ #| awk -F ',' '
+ #{
+ #mem_total = $1;
+ #mem_used = $2;
+ #temp = $3;
+ #mem_used_percent = (100 * mem_used) / mem_total;
+ #printf("[%d%% %dC]", mem_used_percent, temp);
+ #}
+ #'
+#)
+
echo \
"\
E$energy\
\
- G=$graphics_card\
- \
M$memory\
\
- C=[$cpu ${temp}°C ${fan}rpm]\
- \
- L=$load\
+ C=[$load ${temp}°C ${fan}rpm]\
\
D$disk\
\
\
B:$bluetooth_power\
\
- S=$screen_brightness\
- \
- V=$volume\
+ *$screen_brightness\
\
- [$mpd_state $mpd_current]\
+ $volume\
\
- $signal_last_msg_age\
+ [$mpd_state]\
\
$weather\
\