#!/usr/bin/env bash ## Send a status message that includes the time, date, CPU usage, and memory ## usage to a desktop notification daemon that conforms to the freedesktop.org ## Desktop Notifications Specification. ## ## Usage: status [] ## ## Dependencies: GNU awk, GNU coreutils, GNU sed, libnotify, procps, sysstat ## ## I run this script every half hour using systemd unit files and I run it ## manually using a window manager key binding. This script, along with my ## window manager's window switcher, eliminates the need for a taskbar, which ## saves screen real estate. set -euo pipefail shopt -s inherit_errexit [[ " $* " =~ ' --help ' ]] && sed -n 's/^## *//p' "$0" && exit expire_time=${1-0} datetime=$(date '+%-I:%M %p, %A, %B %-d') cpu=$(mpstat 1 1 | awk 'END { print 100 - $12 }') memory=$(free -h | awk 'NR == 2 { print $3 }') message=$datetime$'\n'"CPU $cpu% | Memory $memory" notify-send -t "$expire_time" "$message"