diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..970ea62 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.codex diff --git a/waybar/.config/waybar/config.jsonc b/waybar/.config/waybar/config.jsonc index da01e50..edc14de 100644 --- a/waybar/.config/waybar/config.jsonc +++ b/waybar/.config/waybar/config.jsonc @@ -18,6 +18,7 @@ ], "modules-right": [ "tray", + "custom/print-queue", "network", "bluetooth", "pulseaudio", @@ -64,6 +65,14 @@ "lock": "hyprlock" } }, + "custom/print-queue": { + "exec": "$HOME/.config/waybar/scripts/print-queue.sh", + "return-type": "json", + "interval": 10, + "format": "{}", + "tooltip": true, + "on-click": "$HOME/.config/waybar/scripts/print-queue-view.sh" + }, "hyprland/workspaces": { "all-outputs": false, "sort-by-number": true diff --git a/waybar/.config/waybar/scripts/print-queue-view.sh b/waybar/.config/waybar/scripts/print-queue-view.sh new file mode 100755 index 0000000..cb10918 --- /dev/null +++ b/waybar/.config/waybar/scripts/print-queue-view.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env sh + +if command -v system-config-printer >/dev/null 2>&1; then + exec system-config-printer +fi + +if command -v alacritty >/dev/null 2>&1; then + exec alacritty -e sh -lc ' + while :; do + clear + printf "Print Queue\n" + printf "===========\n\n" + + if ! lpstat -r >/dev/null 2>&1; then + printf "CUPS scheduler is not running.\n" + else + if ! lpstat -o 2>/dev/null | sed "/^[[:space:]]*$/d" | grep . >/dev/null 2>&1; then + printf "No print jobs queued.\n" + else + lpstat -o + fi + fi + + printf "\nRefreshing every 3 seconds. Press Ctrl+C to close." + sleep 3 + done + ' +fi + +exec xdg-open http://localhost:631/jobs/ diff --git a/waybar/.config/waybar/scripts/print-queue.sh b/waybar/.config/waybar/scripts/print-queue.sh new file mode 100755 index 0000000..b6678e1 --- /dev/null +++ b/waybar/.config/waybar/scripts/print-queue.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env sh + +jobs_output="$(lpstat -o 2>/dev/null)" +status=$? + +if [ "$status" -ne 0 ]; then + printf '%s\n' '{"text":"󰐪 n/a","class":"disabled","tooltip":"CUPS is unavailable"}' + exit 0 +fi + +if [ -z "$jobs_output" ]; then + printf '%s\n' '{"text":"","class":"idle","tooltip":"No print jobs queued"}' + exit 0 +fi + +job_count="$(printf '%s\n' "$jobs_output" | sed '/^[[:space:]]*$/d' | wc -l | tr -d ' ')" + +if [ "$job_count" = "1" ]; then + tooltip="1 print job queued" +else + tooltip="$job_count print jobs queued" +fi + +printf '{"text":"󰐪 %s","class":"active","tooltip":"%s"}\n' "$job_count" "$tooltip" diff --git a/waybar/.config/waybar/style.css b/waybar/.config/waybar/style.css index 40a0dba..6344f5e 100644 --- a/waybar/.config/waybar/style.css +++ b/waybar/.config/waybar/style.css @@ -45,6 +45,7 @@ tooltip { #workspaces, #window, #clock, +#custom-print-queue, #network, #bluetooth, #pulseaudio, @@ -63,6 +64,7 @@ tooltip { #custom-launcher, #workspaces, #clock, +#custom-print-queue, #tray { border-left: none; } @@ -72,6 +74,10 @@ tooltip { border-left: none; } +#custom-print-queue { + padding: 0 10px; +} + #network { padding: 0 6px 0 10px; } @@ -153,6 +159,7 @@ tooltip { #custom-launcher:hover, #workspaces button:hover, #network:hover, +#custom-print-queue:hover, #bluetooth:hover, #pulseaudio:hover, #battery:hover,