From f1d0f98a8550a535f8995b445900af071c2c48f2 Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Mon, 7 Dec 2009 12:09:59 -0600 Subject: [PATCH] bin/custom, byobu-config, byobu.1, profiles/common, rpm/byobu.spec, statusrc: add support for a custom status script indicator --- bin/custom | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ byobu-config | 1 + byobu.1 | 2 ++ debian/changelog | 2 ++ profiles/common | 3 ++- rpm/byobu.spec | 1 + statusrc | 2 ++ 7 files changed, 58 insertions(+), 1 deletion(-) create mode 100755 bin/custom diff --git a/bin/custom b/bin/custom new file mode 100755 index 00000000..1c43c78c --- /dev/null +++ b/bin/custom @@ -0,0 +1,48 @@ +#!/bin/sh -e +# +# custom: run the user's custom status scripts +# +# Copyright (C) 2009 Canonical Ltd. +# +# 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" +[ -d "$HOME/.$PKG/bin" ] || exit 0 + +[ -r "/etc/$PKG/statusrc" ] && . "/etc/$PKG/statusrc" +[ -d "/var/run/screen/S-$USER" ] && DIR="/var/run/screen/S-$USER" || DIR="$HOME/.byobu" +NOW=$(date +%s) +CACHE="$DIR/$PKG.custom" + +# Loop over custom scripts +for i in $(ls "$HOME/.$PKG/bin/"[0-9]*_* 2>/dev/null); do + [ -x "$i" ] || continue + script=$(basename "$i") + freq=$(echo "$script" | awk -F_ '{print $1}') + lastrun=$(stat -c %Y "$CACHE.$script") 2>/dev/null || lastrun=0 + expiration=$(expr $lastrun + $freq) + if [ $NOW -ge $expiration ]; then + # Update the cache + $i > "$CACHE.$script" 2>/dev/null + fi + output=$(cat "$CACHE.$script") + if echo "$output" | grep -qs "$ESC{"; then + # User has formatted the colors + echo "$output" + else + # Default to inverted coloring + echo "$INVERT$output$UNDO " + fi +done diff --git a/byobu-config b/byobu-config index a3441126..51bcdac8 100755 --- a/byobu-config +++ b/byobu-config @@ -276,6 +276,7 @@ def readstatus(): status["battery"]=0 status["cpu_count"]=1 status["cpu_freq"]=1 + status["custom"]=1 status["date"]=1 status["disk"]=0 status["ec2_cost"]=0 diff --git a/byobu.1 b/byobu.1 index 2d8aefc7..bcc964a3 100644 --- a/byobu.1 +++ b/byobu.1 @@ -19,6 +19,8 @@ byobu \- wrapper script for seeding a user's byobu configuration and launching s \fBcpu_freq\fP \- the current frequency of the cpu in GHz; displayed in the lower bar toward the right in white text on a light blue background +\fBcustom\fP \- user defined custom scripts; must be executable programs of any kind in \fI$HOME/.byobu/bin\fP; must be named N_NAME, where N is the frequency in seconds to refresh the status indicator, and NAME is the name of the script; N should not be less than 5 seconds; script should echo a small amount of text to standard out, standard error is discared; the indicator will be displayed in the lower panel, in inverted colors to your current background/foreground scheme, unless you manually specify the colors in your script's output; BEWARE, cpu-intensive custom scripts may impact your overall system performance and could upset your system administrator! + \fBdate\fP \- the system date in YYYY-MM-DD formate; displayed in the lower on the far right in the default text color on the default background \fBdisk\fP \- total disk space available and total used on / directory; displayed in the lower bar on the far right in white text on a light purple background; override the default directory by specifying an alternate mount point with MONITORED_DISK=/wherever in \fI$HOME/.byobu/statusrc\fP diff --git a/debian/changelog b/debian/changelog index 0ff0350e..773b2ccb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -45,6 +45,8 @@ byobu (2.40) unreleased; urgency=low there are noisy complaints * byobu-janitor, statusrc: seed the ~/.byobu/status file with the default values, making it easier for users to customize themselves + * bin/custom, byobu-config, byobu.1, profiles/common, rpm/byobu.spec, + statusrc: add support for a custom status script indicator -- Dustin Kirkland Tue, 10 Nov 2009 10:18:20 -0600 diff --git a/profiles/common b/profiles/common index 4fd28cd3..9cc310ca 100644 --- a/profiles/common +++ b/profiles/common @@ -67,6 +67,7 @@ backtick 126 19 19 byobu-status temp_f 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 hardstatus alwayslastline @@ -92,7 +93,7 @@ source $HOME/.byobu/keybindings caption always "%12`%?%-Lw%50L>%?%{=r }%{+b }%n*%f %t%?(%u)%?%12`%?%+Lw%?%11` %=%12`%110`%109`%122`%111`%10`%<" # Status string, last line -hardstatus string '%99`%12` %100`%112`%= %102`%101`%129`%127`%114`%115`%108`%128`%125`%126`%113`%119`%117`%116`%106`%104`%103`%105`%107`%123`%120`%121`' +hardstatus string '%99`%12` %100`%112`%= %130`%102`%101`%129`%127`%114`%115`%108`%128`%125`%126`%113`%119`%117`%116`%106`%104`%103`%105`%107`%123`%120`%121`' # 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/rpm/byobu.spec b/rpm/byobu.spec index 552def3b..f24a3bfd 100644 --- a/rpm/byobu.spec +++ b/rpm/byobu.spec @@ -86,6 +86,7 @@ rm -rf $RPM_BUILD_ROOT /usr/lib/byobu/battery /usr/lib/byobu/cpu_count /usr/lib/byobu/cpu_freq +/usr/lib/byobu/custom /usr/lib/byobu/date /usr/lib/byobu/disk /usr/lib/byobu/ec2_cost diff --git a/statusrc b/statusrc index 2e9c8536..8f49c3ed 100644 --- a/statusrc +++ b/statusrc @@ -25,6 +25,7 @@ arch=0 battery=0 cpu_count=1 cpu_freq=1 +custom=1 date=1 disk=0 ec2_cost=0 @@ -65,6 +66,7 @@ UNDO="$ESC{-}" BOLD1="$ESC{=b }" BOLD2="$ESC{+b }" NONE="$ESC{= }" +INVERT="$ESC{=r }" bw="$ESC{= bw}" bW="$ESC{= bW}"