--- /dev/null
+;; Copyright (c) 2022 Jakub Czajka <jakub@ekhem.eu.org>
+;; License: GPL-3.0 or later.
+;;
+;; status-bar.scm - program for a status bar.
+
+(define-module (conf home status-bar)
+ #:use-module (gnu home services)
+ #:use-module (gnu home services shepherd)
+ #:use-module (gnu packages base)
+ #:use-module (gnu packages gawk)
+ #:use-module (gnu packages linux)
+ #:use-module (gnu packages mail)
+ #:use-module (gnu packages xdisorg)
+ #:use-module (gnu packages xorg)
+ #:use-module (guix build-system trivial)
+ #:use-module (guix gexp)
+ #:use-module (guix licenses)
+ #:use-module (guix packages)
+ #:use-module (guix records)
+ #:use-module (ice-9 match)
+ #:export (status-bar
+ status-bar-configuration
+ status-bar-configuration?
+ status-bar-configuration-package
+ status-bar-service
+ status-bar-service-type))
+
+(define status-bar
+ (package
+ (name "status-bar")
+ (version "1.0")
+ (source
+ (local-file
+ (string-concatenate
+ (list (getenv "GUIX_PACKAGE_PATH")
+ "/scripts/status_bar"))))
+ (build-system trivial-build-system)
+ (arguments
+ '(#:builder
+ (begin
+ (let* ((ins (assoc-ref %build-inputs "source"))
+ (out (assoc-ref %outputs "out"))
+ (file (string-append out "/status_bar")))
+ (mkdir out)
+ (copy-file ins file)
+ (chmod file #o555)))))
+ (synopsis "Script which generates a status bar.")
+ (description "`status-bar` is a shell script which repeatedly prints a status
+bar. The output should be redirected to the desktop.")
+ (home-page "https://git.ekhem.eu.org")
+ (license gpl3+)))
+
+(define-record-type* <status-bar-configuration>
+ status-bar-configuration make-status-bar-configuration
+ status-bar-configuration?
+ (package status-bar-configuration-package
+ (default status-bar)))
+
+(define status-bar-shepherd-service
+ (match-lambda
+ (($ <status-bar-configuration> package)
+ (shepherd-service
+ (provision '(status-bar))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append package "/status_bar"))
+ #:directory
+ (getenv "HOME")
+ #:log-file
+ (string-append (getenv "XDG_LOG_HOME")
+ "/status_bar.log")))
+ (stop #~(make-kill-destructor))
+ (documentation "")))))
+
+(define (install-status-bar-dependencies config)
+ (list alsa-utils gawk notmuch sed xclip xsetroot))
+
+(define status-bar-service-type
+ (service-type
+ (name 'status-bar-service)
+ (extensions
+ (list (service-extension home-profile-service-type
+ install-status-bar-dependencies)
+ (service-extension home-shepherd-service-type
+ (compose list
+ status-bar-shepherd-service))))
+ (default-value (status-bar-configuration))
+ (description "Shepherd service for the `status-bar`.")))
+
+(define status-bar-service
+ (service status-bar-service-type))
--- /dev/null
+#!/bin/sh
+# Copyright (c) 2022 Jakub Czajka <jakub@ekhem.eu.org>
+# License: GPL-3.0 or later.
+
+OLD_UNREAD=0
+OLD_DOWNLOAD=0
+OLD_UPLOAD=0
+
+clock() {
+ echo "📅 $(date "+%T")"
+}
+
+day() {
+ echo "⏰ $(date "+%d-%m-%Y")"
+}
+
+volume() {
+ VOLUME=$(amixer | awk -F"[][]" '/dB/ { print $2 }' | head -n1)
+ if [ "${VOLUME}" = "0%" ]; then
+ echo "🔇 ${VOLUME}"
+ else
+ echo "🔊 ${VOLUME}"
+ fi
+}
+
+battery() {
+ BATTERY_DEVICE="/sys/class/power_supply/BAT0"
+
+ if [ -d "${BATTERY_DEVICE}" ]
+ then
+ STATUS=$(cat "${BATTERY_DEVICE}/status")
+ LEVEL=$(cat "${BATTERY_DEVICE}/capacity")
+ else
+ STATUS="Disconnected"
+ LEVEL="-"
+ fi
+
+ case "${STATUS}" in
+ "Disconnected")
+ BATTERY_ICON="🔋"
+ BATTERY_LEVEL=" n/a"
+ ;;
+ "Charging")
+ BATTERY_ICON="⬆🔋"
+ ;;
+ "Discharging")
+ BATTERY_ICON="⬇🔋"
+ ;;
+ *)
+ esac
+
+ echo "${BATTERY_ICON}${BATTERY_LEVEL}"
+}
+
+session_duration() {
+ UPTIME=$(cut --delimiter=. --field=1 /proc/uptime)
+
+ echo "⌛ $(date --date=@${UPTIME} --universal +%T)"
+}
+
+unread() {
+ NEW_UNREAD=$(notmuch search --output=files tag:unread | wc --lines)
+ MESSAGES="$((${NEW_UNREAD} - ${OLD_UNREAD}))"
+ [ "${MESSAGES}" -gt "0" ] && notify-send "📧 got ${MESSAGES} new message(s)"
+ OLD_UNREAD=${NEW_UNREAD}
+
+ echo "📬 ${OLD_UNREAD}"
+}
+
+language() {
+ CODE=$(echo ${LANG} | sed -e "s/^[a-z\_]*//" -e "s/\..*$//g")
+ echo "🏳 ${CODE}"
+}
+
+bandwidth() {
+ for INTERFACE in /sys/class/net/*
+ do
+ DOWNLOAD_NEW=$(cat "${INTERFACE}/statistics/rx_bytes")
+ DOWNLOAD="$((${DOWNLOAD} + ${DOWNLOAD_NEW}))"
+
+ UPLOAD_NEW=$(cat "${INTERFACE}/statistics/tx_bytes")
+ UPLOAD="$((${UPLOAD} + ${UPLOAD_NEW}))"
+ done
+
+ NEW_DOWNLOAD=$(echo ${DOWNLOAD} | cut --delimiter=" " --fields=2)
+ DOWNLOAD="$((${NEW_DOWNLOAD} - ${OLD_DOWNLOAD}))"
+ OLD_DOWNLOAD=${NEW_DOWNLOAD}
+
+ echo "🌐 ${DOWNLOAD}B/s"
+}
+
+while true
+do
+ TIME=`clock`
+ DATE=`day`
+ VOLUME=`volume`
+ BATTERY=`battery`
+ UPTIME=`session_duration`
+ #UNREAD=`unread`
+ CODE=`language`
+ BANDWIDTH=`bandwidth`
+
+ xsetroot -name "${BANDWIDTH} ${CODE} ${UPTIME} ${BATTERY} ${VOLUME} ${DATE} ${TIME}"
+ sleep 1
+done