From b2f15f9ca51bdf8f4e4525d0ebf055411357dec6 Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Mon, 25 Dec 2023 06:59:26 -0600 Subject: [PATCH] add a package count status item, useful for minimal containers --- usr/lib/byobu/Makefile.am | 2 +- usr/lib/byobu/include/shutil | 1 + usr/lib/byobu/packages | 53 +++++++++++++++++++++++++++++++++++ usr/share/byobu/status/status | 13 +++++---- usr/share/man/man1/byobu.1 | 2 ++ 5 files changed, 64 insertions(+), 7 deletions(-) create mode 100755 usr/lib/byobu/packages diff --git a/usr/lib/byobu/Makefile.am b/usr/lib/byobu/Makefile.am index cf7d035d..ba5186ec 100644 --- a/usr/lib/byobu/Makefile.am +++ b/usr/lib/byobu/Makefile.am @@ -1,3 +1,3 @@ libdirdir = $(prefix)/lib/@PACKAGE@ -libdir_SCRIPTS = apport arch battery cpu_count cpu_freq cpu_temp color custom date disk disk_io distro entropy fan_speed hostname ip_address load_average logo mail memory menu network processes raid reboot_required release services session swap time time_binary time_utc trash updates_available uptime users whoami wifi_quality +libdir_SCRIPTS = apport arch battery cpu_count cpu_freq cpu_temp color custom date disk disk_io distro entropy fan_speed hostname ip_address load_average logo mail memory menu network packages processes raid reboot_required release services session swap time time_binary time_utc trash updates_available uptime users whoami wifi_quality diff --git a/usr/lib/byobu/include/shutil b/usr/lib/byobu/include/shutil index ce4570b8..28e82d40 100755 --- a/usr/lib/byobu/include/shutil +++ b/usr/lib/byobu/include/shutil @@ -258,6 +258,7 @@ status_freq() { menu) _RET=9999991 ;; network) _RET=3 ;; notify_osd) _RET=9999991 ;; + packages) _RET=211 ;; processes) _RET=7 ;; raid) _RET=59 ;; reboot_required) _RET=5 ;; diff --git a/usr/lib/byobu/packages b/usr/lib/byobu/packages new file mode 100755 index 00000000..b8a9f278 --- /dev/null +++ b/usr/lib/byobu/packages @@ -0,0 +1,53 @@ +#!/bin/sh -e +# +# packages: count the number of packages installed +# +# Copyright (C) 2023 Dustin Kirkland +# +# Authors: Dustin Kirkland +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +__packages_detail() { + if eval $BYOBU_TEST dpkg >/dev/null 2>&1; then + dpkg -l | grep ^ii + fi + if eval $BYOBU_TEST snap >/dev/null 2>&1; then + snap list + fi + if eval $BYOBU_TEST apk >/dev/null 2>&1; then + apk info + fi + return +} + +__packages() { + local packages=0 + if eval $BYOBU_TEST dpkg >/dev/null 2>&1; then + count=$(dpkg -l | grep -c ^ii) + packages=$((packages+count)) + fi + if eval $BYOBU_TEST snap >/dev/null 2>&1; then + count=$(snap list | grep -c -v "^Name\s") + packages=$((packages+count)) + fi + if eval $BYOBU_TEST apk >/dev/null 2>&1; then + count=$(apk info | wc -l) + packages=$((packages+count)) + fi + [ -n "$packages" ] || return + color w y; printf "[%s]" "$count"; color -; + +} + +# vi: syntax=sh ts=4 noexpandtab diff --git a/usr/share/byobu/status/status b/usr/share/byobu/status/status index 6baef511..b676e9ac 100644 --- a/usr/share/byobu/status/status +++ b/usr/share/byobu/status/status @@ -5,6 +5,7 @@ # and $HOME/.byobu otherwise. # # Copyright (C) 2009-2011 Canonical Ltd. +# Copyright (C) 2023 Dustin Kirkland # # Authors: Dustin Kirkland # @@ -26,13 +27,13 @@ screen_upper_left="color" screen_upper_right="color whoami hostname ip_address menu" screen_lower_left="color logo distro release #arch session" -screen_lower_right="color network #disk_io custom #entropy raid reboot_required updates_available #apport #services #mail users uptime #fan_speed #cpu_temp battery wifi_quality #processes load_average cpu_count cpu_freq memory #swap disk #time_utc date time" +screen_lower_right="color network #disk_io custom #entropy raid reboot_required updates_available #apport #services #mail users uptime #fan_speed #cpu_temp battery wifi_quality #processes #packages load_average cpu_count cpu_freq memory #swap disk #time_utc date time" # Tmux has one status line, with 2 halves for status tmux_left="logo #distro release #arch session" # You can have as many tmux right lines below here, and cycle through them using Shift-F5 -tmux_right="#network #disk_io #custom #entropy raid reboot_required updates_available #apport #services #mail #users uptime #fan_speed #cpu_temp #battery #wifi_quality #processes load_average cpu_count cpu_freq memory #swap disk #whoami #hostname #ip_address #time_utc date time" -#tmux_right="network disk_io uptime processes load_average cpu_count cpu_freq memory disk date time" # Tailored for inside of containers -#tmux_right="network #disk_io #custom entropy raid reboot_required updates_available #apport #services #mail users uptime fan_speed cpu_temp battery wifi_quality #processes load_average cpu_count cpu_freq memory #swap #disk whoami hostname ip_address #time_utc date time" -#tmux_right="network #disk_io custom #entropy raid reboot_required updates_available #apport #services #mail users uptime #fan_speed #cpu_temp battery wifi_quality #processes load_average cpu_count cpu_freq memory #swap #disk #whoami #hostname ip_address #time_utc date time" -#tmux_right="#network disk_io #custom entropy #raid #reboot_required #updates_available #apport #services #mail #users #uptime fan_speed cpu_temp #battery #wifi_quality #processes #load_average #cpu_count #cpu_freq #memory #swap whoami hostname ip_address #time_utc disk date time" +tmux_right="#network #disk_io #custom #entropy raid reboot_required updates_available #apport #services #mail #users uptime #fan_speed #cpu_temp #battery #wifi_quality #processes #packages load_average cpu_count cpu_freq memory #swap disk #whoami #hostname #ip_address #time_utc date time" +#tmux_right="network disk_io uptime processes packages load_average cpu_count cpu_freq memory disk date time" # Tailored for inside of containers +#tmux_right="network #disk_io #custom entropy raid reboot_required updates_available #apport #services #mail users uptime fan_speed cpu_temp battery wifi_quality #processes #packages load_average cpu_count cpu_freq memory #swap #disk whoami hostname ip_address #time_utc date time" +#tmux_right="network #disk_io custom #entropy raid reboot_required updates_available #apport #services #mail users uptime #fan_speed #cpu_temp battery wifi_quality #processes #packages load_average cpu_count cpu_freq memory #swap #disk #whoami #hostname ip_address #time_utc date time" +#tmux_right="#network disk_io #custom entropy #raid #reboot_required #updates_available #apport #services #mail #users #uptime fan_speed cpu_temp #battery #wifi_quality #processes #packages #load_average #cpu_count #cpu_freq #memory #swap whoami hostname ip_address #time_utc disk date time" diff --git a/usr/share/man/man1/byobu.1 b/usr/share/man/man1/byobu.1 index 4e3fc9b8..3923cb39 100644 --- a/usr/share/man/man1/byobu.1 +++ b/usr/share/man/man1/byobu.1 @@ -79,6 +79,8 @@ The background colors of the \fBbyobu\fP status lines can be adjusted by editing \fBnotify_osd\fP \- Send on-screen notification messages to screen's notification buffer +\fBpackages\fP \- total number of packages installed on the system; displayed in the lower bar in yellow text on a white background inside of square brackets, '[xxx]' + \fBprocesses\fP \- total number of processes running on the system; displayed in the lower bar in white text on a dark yellow background with a trailing '&' indicating 'background processes' \fBreboot_required\fP \- symbol present if a reboot is required following a system update; displayed in the lower bar white text on a blue background by the symbol '(R)'; additionally, reboot_required will print '' in white text on a blue background, if Byobu requires you to reload your profile to affect some changes; it will also detect if your system is currently in \fBpowernap\fP(8) state and if so print '.zZ'; if your system is currently performing an \fBunattended-upgrade\fP(1) you will see a white warning sign on a red background.