From e99b7ac02441ee6b8374717316db69e8835bda4d Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Sun, 15 May 2011 23:03:29 +0200 Subject: [PATCH] * usr/bin/byobu, usr/bin/byobu-reconnect-sockets, usr/lib/byobu/.shutil: - source _shutil - exec screen -v rather than waiting and exiting - use HOSTNAME if set (it is set in bash), avoiding the fork for 'hostname' - use 'uncommented_lines' function in _shutil rather than grep - use 'command -v' (posix sh shell builtin) rather than 'which' - mention that byobu-janitor should not be called every time --- debian/changelog | 11 +++++++++++ usr/bin/byobu | 20 ++++++++++++-------- usr/bin/byobu-reconnect-sockets | 8 +------- usr/lib/byobu/.shutil | 25 +++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 15 deletions(-) create mode 100644 usr/lib/byobu/.shutil diff --git a/debian/changelog b/debian/changelog index d13b1bd6..d5484476 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,7 +1,18 @@ byobu (4.2) unreleased; urgency=low + [ Dustin Kirkland ] * usr/bin/byobu-config: remove debug output, LP: #782372 + [ Scott Moser ] + * usr/bin/byobu, usr/bin/byobu-reconnect-sockets, + usr/lib/byobu/.shutil: + - source _shutil + - exec screen -v rather than waiting and exiting + - use HOSTNAME if set (it is set in bash), avoiding the fork for 'hostname' + - use 'uncommented_lines' function in _shutil rather than grep + - use 'command -v' (posix sh shell builtin) rather than 'which' + - mention that byobu-janitor should not be called every time + -- Dustin Kirkland Fri, 13 May 2011 18:58:03 +0200 byobu (4.1-0ubuntu1) oneiric; urgency=low diff --git a/usr/bin/byobu b/usr/bin/byobu index ed14d75b..ca036291 100755 --- a/usr/bin/byobu +++ b/usr/bin/byobu @@ -25,9 +25,10 @@ export BYOBU_PREFIX RUN="$SOCKETDIR/S-$USER" DATA="$HOME/.$PKG" +. "${BYOBU_PREFIX}/usr/lib/${PKG}/.shutil" if [ ! -x "$BYOBU_PREFIX/bin/$PKG" ]; then - echo "ERROR: Cannot find $BYOBU_PREFIX/bin/$PKG" 2>&1 - echo "ERROR: If you have installed it elsewhere, export BYOBU_PREFIX in your shell" 2>&1 + error "Cannot find $BYOBU_PREFIX/bin/$PKG" + error "If you have installed it elsewhere, export BYOBU_PREFIX in your shell" exit 1 fi @@ -36,7 +37,7 @@ if [ "$#" = "1" ]; then case "$1" in -v|--version) echo "$PKG version $VERSION" - screen -v + exec screen -v exit 0 ;; esac @@ -51,7 +52,7 @@ fi byobu-janitor --force # Set the window title -[ -z "$BYOBU_NO_TITLE" ] || printf "\033]0;${USER}@$(hostname) - ${PKG}\007" +[ -z "$BYOBU_NO_TITLE" ] || printf "\033]0;${USER}@${HOSTNAME:-$(hostname)} - ${PKG}\007" # Allow override of default window list, with BYOBU_WINDOWS environment variable CUSTOM_WINDOW_SET=0 @@ -68,14 +69,17 @@ fi export BYOBU_WINDOWS # Launch shell, unless the user has default windows set to launch -grep -qs "^[^#]" "$BYOBU_WINDOWS" && DEFAULT_WINDOW= || DEFAULT_WINDOW="shell" +uncommented_lines < "$BYOBU_WINDOWS" && DEFAULT_WINDOW= || DEFAULT_WINDOW="shell" # Check if our terminfo supports 256 colors -$(which tput >/dev/null) && [ $(tput colors 2>/dev/null || echo 0) -eq 256 ] && SCREEN_TERM="-T screen-256color" +if command -v tput >/dev/null; then + if [ "$(tput colors 2>/dev/null || echo 0)" = "256" ]; then + SCREEN_TERM="-T screen-256color" + fi +fi # Drop a symlink to the ssh socket in $HOME, since we can ensure that exists if [ -S "$SSH_AUTH_SOCK" ] && [ ! -h "$SSH_AUTH_SOCK" ]; then - rm -f "$DATA/.ssh-agent" ln -sf "$SSH_AUTH_SOCK" "$DATA/.ssh-agent" fi @@ -88,7 +92,7 @@ else fi NAME="-S $PKG" # Zero out $NAME if user has specified a -S -for i in $@; do +for i in "$@"; do case $i in -*S|-ls|-list) NAME= ;; esac done # Now let's execute screen! diff --git a/usr/bin/byobu-reconnect-sockets b/usr/bin/byobu-reconnect-sockets index f961c36a..399ab86b 100755 --- a/usr/bin/byobu-reconnect-sockets +++ b/usr/bin/byobu-reconnect-sockets @@ -23,13 +23,7 @@ PKG="byobu" -# newest(file,file,file..) -# return the newest file in the list -newest() { - local c="$1" i - for i in "$@"; do [ "$i" -nt "$c" ] && c="$i"; done - [ -e "$c" ] && _RET="$c" -} +. "${BYOBU_PREFIX}/usr/lib/${PKG}/.shutil" case "$-" in *i*) diff --git a/usr/lib/byobu/.shutil b/usr/lib/byobu/.shutil new file mode 100644 index 00000000..8d022448 --- /dev/null +++ b/usr/lib/byobu/.shutil @@ -0,0 +1,25 @@ +# uncommented_lines(char=#) +# does the standard input have lines that do not start with 'char'? +uncommented_lines() { + local line chr="${1:-#}" + while read line; do + [ "${line#${chr}}" = "${line}" ] && return 0; + done + return 1 +} + +# newest(file,file,file..) +# return the newest file in the list +newest() { + local c="$1" i + for i in "$@"; do [ "$i" -nt "$c" ] && c="$i"; done + [ -e "$c" ] && _RET="$c" +} + +error() { + echo "ERROR: " "$@" 1>&2 +} + +fail() { + [ $# -eq 0 ] || error "$@"; exit 1; +}