diff --git a/Makefile.am b/Makefile.am index 684bc285..7c0106ba 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,6 +4,7 @@ SUBDIRS = etc/byobu \ usr/share/byobu/keybindings \ usr/share/byobu/pixmaps \ usr/share/byobu/profiles \ + usr/share/byobu/status \ usr/share/byobu/tests \ usr/share/byobu/windows \ usr/share/doc/byobu \ diff --git a/configure.ac b/configure.ac index ced18bf4..f0c44d8e 100644 --- a/configure.ac +++ b/configure.ac @@ -22,6 +22,7 @@ AC_OUTPUT(Makefile \ usr/share/byobu/keybindings/Makefile \ usr/share/byobu/pixmaps/Makefile \ usr/share/byobu/profiles/Makefile \ + usr/share/byobu/status/Makefile \ usr/share/byobu/tests/Makefile \ usr/share/byobu/windows/Makefile \ usr/share/doc/byobu/Makefile \ diff --git a/debian/changelog b/debian/changelog index 52878a99..778de029 100644 --- a/debian/changelog +++ b/debian/changelog @@ -28,6 +28,29 @@ byobu (4.18) unreleased; urgency=low - support tmux -V version * usr/lib/byobu/.shutil: - update ec2 detection method + * === added directory usr/share/byobu/status, configure.ac, + etc/byobu/statusrc, experimental/byobu-status-all => usr/bin/byobu- + statusd, Makefile.am, usr/bin/byobu-janitor, usr/bin/byobu-status- + print, usr/bin/Makefile.am, usr/lib/byobu/color, + usr/lib/byobu/.constants, usr/lib/byobu/Makefile.am, + usr/lib/byobu/.shutil, usr/share/byobu/profiles/common, + usr/share/byobu/status/1, usr/share/byobu/status/2, + usr/share/byobu/status/3, usr/share/byobu/status/4, + usr/share/byobu/status/Makefile.am: + - add shared configurations for status ordering + - install symlinks to status ordering + - add status script for status colors + - move color function to shared utils + - add stub for tmux color support + - add byobu-statusd, daemon to cache and update status information in the + run directory as the information expires + - add byobu-status-print, script to concatenate status per ordered + configuration + - move byobu backend support below BYOBU_CONFIG_DIR determination + - move status frequencies to a shared utility function + - drop the backtick commands for all the individual status functions + - add the backtick commands for the 4 quadrants of status + - update the hardstatus line accordingly [ James Spencer ] * usr/lib/byobu/.constants: diff --git a/etc/byobu/statusrc b/etc/byobu/statusrc index 42299b2a..9d91778f 100644 --- a/etc/byobu/statusrc +++ b/etc/byobu/statusrc @@ -23,6 +23,7 @@ apport=0 arch=0 battery=1 +color=1 cpu_count=1 cpu_freq=1 cpu_temp=0 diff --git a/experimental/byobu-status-all b/experimental/byobu-status-all deleted file mode 100755 index 35e800fe..00000000 --- a/experimental/byobu-status-all +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh - -LIBDIR=/home/kirkland/src/byobu/byobu/usr/lib/byobu -. "$LIBDIR/.constants" -. "$LIBDIR/.shutil" - -mkdir -p "$BYOBU_RUN_DIR/status" -for i in "$LIBDIR/"*; do - case "$i" in - */Makefile.am) - true - ;; - *time_binary) - true - ;; - *) - #printf "Sourcing [$i]...\n" - . "$i" - j=${i##*/} - #printf "Running [__$j]...[" - eval "__$j" > "$BYOBU_RUN_DIR/status/$j" - #printf "]\n" - ;; - esac -done -exit 0 - - -[ -n "$2" ] && eval "__${1}_detail" || eval "__$1" diff --git a/usr/bin/Makefile.am b/usr/bin/Makefile.am index 3a4ceb15..771c0f07 100644 --- a/usr/bin/Makefile.am +++ b/usr/bin/Makefile.am @@ -1,2 +1,2 @@ -bin_SCRIPTS = byobu byobu-config byobu-ctrl-a byobu-disable byobu-enable byobu-export byobu-janitor byobu-launch byobu-launcher byobu-launcher-install byobu-launcher-uninstall byobu-quiet byobu-reconnect-sockets byobu-select-profile byobu-select-session byobu-silent byobu-status byobu-status-detail byobu-shell +bin_SCRIPTS = byobu byobu-config byobu-ctrl-a byobu-disable byobu-enable byobu-export byobu-janitor byobu-launch byobu-launcher byobu-launcher-install byobu-launcher-uninstall byobu-quiet byobu-reconnect-sockets byobu-select-profile byobu-select-session byobu-silent byobu-status byobu-statusd byobu-status-detail byobu-status-print byobu-shell diff --git a/usr/bin/byobu-janitor b/usr/bin/byobu-janitor index 4e2d07c7..e09b1a5e 100755 --- a/usr/bin/byobu-janitor +++ b/usr/bin/byobu-janitor @@ -40,6 +40,11 @@ command -v greadlink >/dev/null && READLINK="greadlink" || READLINK="readlink" # Create byobu-exchange buffer file, with secure permissions, if it doesn't exist [ -e "$BYOBU_RUN_DIR/printscreen" ] || install -m 600 /dev/null "$BYOBU_RUN_DIR/printscreen" +# Set up status ordering symlinks +for i in 1 2 3 4; do + [ -e "$BYOBU_CONFIG_DIR/status.$i" ] || ln -s "${BYOBU_PREFIX}/share/${PKG}/status/$i" "$BYOBU_CONFIG_DIR/status.$i" +done + # Affects: users who launched using sudo, such that their config dir # is not writable by them if [ -d "$BYOBU_CONFIG_DIR" ] && [ ! -w "$BYOBU_CONFIG_DIR" ]; then diff --git a/usr/bin/byobu-status-print b/usr/bin/byobu-status-print new file mode 100755 index 00000000..291d3c5b --- /dev/null +++ b/usr/bin/byobu-status-print @@ -0,0 +1,35 @@ +#!/bin/sh +# +# byobu-status-print: concatenate the status cache +# +# Copyright (C) 2011 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 . + +PKG="byobu" +[ -z "${BYOBU_PREFIX}" ] && export BYOBU_PREFIX="/usr" || export BYOBU_PREFIX +. "${BYOBU_PREFIX}/lib/${PKG}/.constants" + +for i in $(cat "$BYOBU_CONFIG_DIR/status.$1"); do + cache="$BYOBU_RUN_DIR/status/$i" + if [ -s "$cache" ]; then + read c < "$cache" + printf "%s" "$c" + case "$i" in + color|time) true ;; + *) printf " " ;; + esac + fi +done diff --git a/usr/bin/byobu-statusd b/usr/bin/byobu-statusd new file mode 100755 index 00000000..e3b64280 --- /dev/null +++ b/usr/bin/byobu-statusd @@ -0,0 +1,74 @@ +#!/bin/sh +# +# byobu-status-print: concatenate the status cache +# +# Copyright (C) 2011 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 . + +PKG="byobu" +[ -z "${BYOBU_PREFIX}" ] && export BYOBU_PREFIX="/usr" || export BYOBU_PREFIX +. "${BYOBU_PREFIX}/lib/${PKG}/.common" + +# Clean and create cache directories +rm -rf "$BYOBU_RUN_DIR/status" "$BYOBU_RUN_DIR/.last" +mkdir -p "$BYOBU_RUN_DIR/status" "$BYOBU_RUN_DIR/.last" + +# Source configurations +for i in "/etc/$PKG/statusrc" "$BYOBU_CONFIG_DIR/status" "$BYOBU_CONFIG_DIR/statusrc"; do + [ -r "$i" ] && . "$i" +done + +# Run each status function as necessary +while true; do + # Make sure status is not disabled + if [ -f "$BYOBU_CONFIG_DIR/status.disable" ]; then + rm -f "$BYOBU_RUN_DIR/status"/* "$BYOBU_RUN_DIR/.last"/* + exit 0 + fi + now=$(date +%s) + # Re-source configuration, if changed since last run + for i in "/etc/$PKG/statusrc" "$BYOBU_CONFIG_DIR/status" "$BYOBU_CONFIG_DIR/statusrc"; do + [ -r "$i" ] && [ "$i" -nt "$BYOBU_RUN_DIR/status" ] && . "$i" + done + for i in "$BYOBU_PREFIX/lib/$PKG/"*; do + case "$i" in + */time_binary|*/Makefile.am) continue ;; + esac + i=${i##*/} + cache="$BYOBU_RUN_DIR/status/$i" + last="$BYOBU_RUN_DIR/.last/$i" + # Check if this status is enabled + eval x="\$$i" + if [ "$x" != "1" ]; then + rm -f "$cache" "$last" + continue + fi + [ -r "$last" ] && read lastrun < "$last" || lastrun=0 + status_freq "$i" + expiry=$(($lastrun+$_RET)) + find_script "$i" && path="$_RET" || path=/dev/null + if [ $now -ge $expiry ] || [ "$path" -nt "$last" ]; then + # Re-source status function, if changed since last run + if [ "$path" -nt "$last" ] || [ ! -e "$last" ]; then + . "$path" + fi + eval "__$i" > "$cache" + echo "$now" > "$last" + fi + done + sleep 2 +done +exit 0 diff --git a/usr/lib/byobu/.constants b/usr/lib/byobu/.constants index 83651400..e4db2060 100755 --- a/usr/lib/byobu/.constants +++ b/usr/lib/byobu/.constants @@ -20,22 +20,6 @@ PKG="byobu" -# Support two different backends (screen/tmux) -if [ -z "$BYOBU_BACKEND" ]; then - [ -r "/etc/byobu/backend" ] && . "/etc/byobu/backend" - [ -r "$BYOBU_CONFIG_DIR/backend" ] && . "$BYOBU_CONFIG_DIR/backend" -fi -case "$BYOBU_BACKEND" in - tmux) - export BYOBU_BACKEND - BYOBU_ARG_VERSION="-V" - ;; - *) - export BYOBU_BACKEND="screen" - BYOBU_ARG_VERSION="-v" - ;; -esac - # Create and set the user configuration directory if [ -d "$XDG_CONFIG_HOME" ] && mkdir -p "$XDG_CONFIG_HOME/$PKG"; then export BYOBU_CONFIG_DIR="$XDG_CONFIG_HOME/$PKG" @@ -82,3 +66,19 @@ else ICON_TRASH="T" ICON_WIFI= fi + +# Support two different backends (screen/tmux) +if [ -z "$BYOBU_BACKEND" ]; then + [ -r "/etc/byobu/backend" ] && . "/etc/byobu/backend" + [ -r "$BYOBU_CONFIG_DIR/backend" ] && . "$BYOBU_CONFIG_DIR/backend" +fi +case "$BYOBU_BACKEND" in + tmux) + export BYOBU_BACKEND + BYOBU_ARG_VERSION="-V" + ;; + *) + export BYOBU_BACKEND="screen" + BYOBU_ARG_VERSION="-v" + ;; +esac diff --git a/usr/lib/byobu/.shutil b/usr/lib/byobu/.shutil index 52e8d85b..a82b010f 100755 --- a/usr/lib/byobu/.shutil +++ b/usr/lib/byobu/.shutil @@ -19,7 +19,42 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -color 2>/dev/null || color() { true; } +# Define colors +color_screen() { + ESC="\005" + case "$1" in + "") return 0 ;; + -) printf "$ESC{-}" ;; + --) printf "$ESC{-} " ;; + esc) printf "$ESC" ;; + bold1) printf "$ESC{=b }" ;; + bold2) printf "$ESC{+b }" ;; + none) printf "$ESC{= }" ;; + invert) printf "$ESC{=r }" ;; + *) + if [ "$#" = "2" ]; then + [ "$MONOCHROME" = "1" ] && printf "$ESC{= }" || printf "$ESC{= $1$2}" + else + [ "$MONOCHROME" = "1" ] && printf "$ESC{=$1 }" || printf "$ESC{=$1 $2$3}" + fi + ;; + esac +} + +color_tmux() { + true +} + +color() { + case "$BYOBU_BACKEND" in + tmux) + color_tmux "$@" + ;; + *) + color_screen "$@" + ;; + esac +} # uncommented_lines(char=#) # does the standard input have lines that do not start with 'char'? @@ -116,47 +151,54 @@ metadata_available() { } status_freq() { +# Define status frequencies +# Use prime number intervals, to decrease collisions, which +# yields some less expensive status updates. +# ~86000 ~1 day +# ~600 ~10 minutes +# ~180 ~3 minutes +# ~60 ~1 minute case "$1" in - apport)_RET=67 ;; - arch)_RET=9999999 ;; - battery)_RET=61 ;; - color)_RET=9999999 ;; - cpu_count) _RET=5 ;; - cpu_freq) _RET=2 ;; - cpu_temp) _RET=19 ;; - custom) _RET=5 ;; - date) _RET=28793 ;; - disk) _RET=13 ;; - disk_io) _RET=3 ;; - ec2_cost) _RET=601 ;; - fan_speed) _RET=23 ;; - hostname) _RET=607 ;; - ip_address) _RET=127 ;; - load_average) _RET=2 ;; - logo) _RET=9999999 ;; - mail) _RET=5 ;; - mem_available) _RET=47 ;; - mem_used) _RET=13 ;; - menu) _RET=9999999 ;; - network) _RET=3 ;; - notify_osd) _RET=0 ;; - processes) _RET=7 ;; - raid) _RET=7 ;; - rcs_cost) _RET=613 ;; + apport) _RET=67 ;; + arch) _RET=9999999 ;; + battery) _RET=61 ;; + color) _RET=9999999 ;; + cpu_count) _RET=5 ;; + cpu_freq) _RET=2 ;; + cpu_temp) _RET=19 ;; + custom) _RET=5 ;; + date) _RET=28793 ;; + disk) _RET=13 ;; + disk_io) _RET=3 ;; + ec2_cost) _RET=601 ;; + fan_speed) _RET=23 ;; + hostname) _RET=607 ;; + ip_address) _RET=127 ;; + load_average) _RET=2 ;; + logo) _RET=9999999 ;; + mail) _RET=5 ;; + mem_available) _RET=47 ;; + mem_used) _RET=13 ;; + menu) _RET=9999999 ;; + network) _RET=3 ;; + notify_osd) _RET=9999999 ;; + processes) _RET=7 ;; + raid) _RET=7 ;; + rcs_cost) _RET=613 ;; reboot_required) _RET=5 ;; - release) _RET=599 ;; - services) _RET=53 ;; - swap) _RET=19 ;; - time) _RET=9999999 ;; - time_binary) _RET=23 ;; - time_utc) _RET=11 ;; - trash) _RET=9999999 ;; + release) _RET=599 ;; + services) _RET=53 ;; + swap) _RET=19 ;; + time) _RET=9999999 ;; + time_binary) _RET=23 ;; + time_utc) _RET=11 ;; + trash) _RET=9999999 ;; updates_available) _RET=7 ;; - uptime) _RET=29 ;; - users) _RET=11 ;; - whoami) _RET=86029 ;; - wifi_quality) _RET=17 ;; - *) _RET=9999999 ;; + uptime) _RET=29 ;; + users) _RET=11 ;; + whoami) _RET=86029 ;; + wifi_quality) _RET=17 ;; + *) _RET=9999999 ;; esac } diff --git a/usr/lib/byobu/Makefile.am b/usr/lib/byobu/Makefile.am index c2d4e775..c2aa797b 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 custom date disk disk_io ec2_cost fan_speed hostname ip_address load_average logo mail mem_available mem_used menu network .notify_osd notify_osd processes raid rcs_cost reboot_required release services swap time time_binary time_utc trash updates_available uptime users whoami wifi_quality .common .constants .shutil +libdir_SCRIPTS = apport arch battery cpu_count cpu_freq cpu_temp color custom date disk disk_io ec2_cost fan_speed hostname ip_address load_average logo mail mem_available mem_used menu network .notify_osd notify_osd processes raid rcs_cost reboot_required release services swap time time_binary time_utc trash updates_available uptime users whoami wifi_quality .common .constants .shutil diff --git a/usr/lib/byobu/color b/usr/lib/byobu/color new file mode 100755 index 00000000..64b2720c --- /dev/null +++ b/usr/lib/byobu/color @@ -0,0 +1,31 @@ +#!/bin/sh -e +# +# color: print the background/foreground color escape codes +# +# Copyright (C) 2011 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 . + +__color_detail() { + true +} + +__color() { + [ -z "$FOREGROUND" ] && FOREGROUND="w" + [ -z "$BACKGROUND" ] && BACKGROUND="k" + printf "\005{= $BACKGROUND$FOREGROUND}" +} + +# vi: syntax=sh ts=4 noexpandtab diff --git a/usr/share/byobu/profiles/common b/usr/share/byobu/profiles/common index 66f353ed..e4f81544 100644 --- a/usr/share/byobu/profiles/common +++ b/usr/share/byobu/profiles/common @@ -28,58 +28,11 @@ msgminwait 0 defutf8 on deflogin on -# Define status commands -# Use prime number intervals, to decrease collisions, which -# yields some less expensive status updates. -# ~86000 ~1 day -# ~600 ~10 minutes -# ~180 ~3 minutes -# ~60 ~1 minute -backtick 10 9999999 9999999 byobu-janitor -backtick 11 9999999 9999999 printf "\005-1=" -backtick 12 9999999 9999999 byobu-status color -backtick 13 0 0 byobu-status notify_osd -backtick 99 9999999 9999999 byobu-status logo -backtick 100 599 599 byobu-status release -backtick 101 7 7 byobu-status updates_available -backtick 102 5 5 byobu-status reboot_required -backtick 103 2 2 byobu-status cpu_freq -backtick 104 5 5 byobu-status cpu_count -backtick 105 47 47 byobu-status mem_available -backtick 106 2 2 byobu-status load_average -backtick 107 13 13 byobu-status mem_used -backtick 108 601 601 byobu-status ec2_cost -backtick 109 607 607 byobu-status hostname -backtick 110 86029 86029 byobu-status whoami -backtick 111 9999999 9999999 byobu-status menu -backtick 112 9999999 9999999 byobu-status arch -backtick 113 61 61 byobu-status battery -backtick 114 11 11 byobu-status users -backtick 115 29 29 byobu-status uptime -backtick 116 7 7 byobu-status processes -backtick 117 3 3 byobu-status network -backtick 118 9999999 9999999 true -backtick 119 17 17 byobu-status wifi_quality -backtick 120 28793 28793 byobu-status date -backtick 121 9999999 9999999 byobu-status time -backtick 122 127 127 byobu-status ip_address -backtick 123 13 13 byobu-status disk -backtick 124 9999999 9999999 true -backtick 125 19 19 byobu-status cpu_temp -backtick 126 9999999 9999999 true -backtick 127 5 5 byobu-status mail -backtick 128 23 23 byobu-status fan_speed -backtick 129 67 67 byobu-status apport -backtick 130 5 5 byobu-status custom -backtick 131 53 53 byobu-status services -backtick 132 11 11 byobu-status time_utc -backtick 133 3 3 byobu-status disk_io -backtick 134 613 613 byobu-status rcs_cost -backtick 135 7 7 byobu-status raid -backtick 136 19 19 byobu-status swap -backtick 137 23 23 byobu-status time_binary - -hardstatus alwayslastline +backtick 10 9999999 9999999 byobu-janitor +backtick 1001 1 1 byobu-status-print 1 +backtick 1002 1 1 byobu-status-print 2 +backtick 1003 1 1 byobu-status-print 3 +backtick 1004 1 1 byobu-status-print 4 # The following line would turn off alternate Screen switching in xterms, # so that text in Screen will go into the xterm's scrollback buffer. @@ -114,7 +67,8 @@ setenv SSH_AUTH_SOCK $BYOBU_CONFIG_DIR/.ssh-agent caption always "%12`%?%-Lw%50L>%?%{=r}%n*%f %t%?(%u)%?%{-}%12`%?%+Lw%?%11` %=%12`%110`%109`%122`%111`%10`%<" # Status string, last line -hardstatus string '%99`%{-}%{=r}%12` %100`%112`%=%117`%133`%130`%135`%102`%101`%129`%131`%127`%114`%115`%108`%134`%128`%125`%126`%113`%119`%116`%106`%104`%103`%105`%107`%136`%123`%137`%132`%120`%121`' +hardstatus alwayslastline +hardstatus string '%1003`%=%1004`' # NOTE: Older version of Screen have an arbitrary limit of only being able # to change colors 16 times in this 'hardstatus string'. diff --git a/usr/share/byobu/status/1 b/usr/share/byobu/status/1 new file mode 100644 index 00000000..e69de29b diff --git a/usr/share/byobu/status/2 b/usr/share/byobu/status/2 new file mode 100644 index 00000000..e69de29b diff --git a/usr/share/byobu/status/3 b/usr/share/byobu/status/3 new file mode 100644 index 00000000..4eb787f7 --- /dev/null +++ b/usr/share/byobu/status/3 @@ -0,0 +1,4 @@ +color +logo +release +arch diff --git a/usr/share/byobu/status/4 b/usr/share/byobu/status/4 new file mode 100644 index 00000000..7c399266 --- /dev/null +++ b/usr/share/byobu/status/4 @@ -0,0 +1,29 @@ +network +disk_io +custom +raid +reboot_required +updates_available +apport +services +mail +users +uptime +ec2_cost +rcs_cost +fan_speed +cpu_temp +battery +wifi_quality +processes +load_average +cpu_count +cpu_freq +mem_available +mem_used +swap +disk +time_binary +time_utc +date +time diff --git a/usr/share/byobu/status/Makefile.am b/usr/share/byobu/status/Makefile.am new file mode 100644 index 00000000..00fedfba --- /dev/null +++ b/usr/share/byobu/status/Makefile.am @@ -0,0 +1,2 @@ +statusdir = $(datadir)/@PACKAGE@/status +status_DATA = 1 2 3 4