feat: add printer cups in bar
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.codex
|
||||
@@ -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
|
||||
|
||||
30
waybar/.config/waybar/scripts/print-queue-view.sh
Executable file
30
waybar/.config/waybar/scripts/print-queue-view.sh
Executable file
@@ -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/
|
||||
24
waybar/.config/waybar/scripts/print-queue.sh
Executable file
24
waybar/.config/waybar/scripts/print-queue.sh
Executable file
@@ -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"
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user