From cdb17801818f3bd508a1bf3eb15693b8d281ba24 Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Fri, 2 Aug 2013 17:16:28 -0500 Subject: [PATCH] * usr/bin/byobu-enable-prompt, usr/lib/byobu/distro, usr/lib/byobu/include/shutil, usr/lib/byobu/logo: - use a common get_distro function in a couple of places --- debian/changelog | 3 +++ usr/bin/byobu-enable-prompt | 3 ++- usr/lib/byobu/distro | 41 ++---------------------------- usr/lib/byobu/include/shutil | 48 ++++++++++++++++++++++++++++++++++++ usr/lib/byobu/logo | 22 ----------------- 5 files changed, 55 insertions(+), 62 deletions(-) diff --git a/debian/changelog b/debian/changelog index cfdd1acc..17edfc4b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -9,6 +9,9 @@ byobu (5.50) unreleased; urgency=low * usr/bin/byobu-disable-prompt, usr/bin/byobu-enable-prompt: - use ubuntu themed colors for the prompt if running on Ubuntu + * usr/bin/byobu-enable-prompt, usr/lib/byobu/distro, + usr/lib/byobu/include/shutil, usr/lib/byobu/logo: + - use a common get_distro function in a couple of places -- Dustin Kirkland Sun, 28 Jul 2013 19:51:39 -0500 diff --git a/usr/bin/byobu-enable-prompt b/usr/bin/byobu-enable-prompt index 7b1862ce..1867ea0e 100755 --- a/usr/bin/byobu-enable-prompt +++ b/usr/bin/byobu-enable-prompt @@ -22,8 +22,9 @@ PKG="byobu" [ -z "${BYOBU_PREFIX}" ] && export BYOBU_PREFIX="/usr" || export BYOBU_PREFIX . "${BYOBU_PREFIX}/lib/${PKG}/include/common" +get_distro +DISTRO="$_RET" byobu-disable-prompt || true -DISTRO=$(lsb_release -s -d) case $DISTRO in Ubuntu*) cat >>"$HOME/.bashrc" </dev/null 2>&1; then - # If lsb_release is available, use it - local r=$(lsb_release -s -d) - case "$r" in - Ubuntu*) - # Use the -d if an Ubuntu LTS - DISTRO="Ubuntu" - ;; - *) - # But for other distros the description - # is too long, so build from -i and -r - DISTRO=$(lsb_release -s -i) - ;; - esac - elif $BYOBU_TEST sw_vers >/dev/null 2>&1; then - DISTRO="$(sw_vers -productName)" - elif $BYOBU_TEST uname >/dev/null 2>&1; then - DISTRO="$(uname -s)" else - DISTRO="Byobu" + get_distro + DISTRO="$_RET" fi - [ -n "$DISTRO" ] || return color bold2; printf "%s" "$DISTRO"; color -- } diff --git a/usr/lib/byobu/include/shutil b/usr/lib/byobu/include/shutil index 96087bd1..547f6367 100755 --- a/usr/lib/byobu/include/shutil +++ b/usr/lib/byobu/include/shutil @@ -310,4 +310,52 @@ get_network_interface() { fi } +get_distro() { + local distro="${DISTRO}" + if [ -n "$DISTRO" ]; then + # user defined + true + elif [ -r "/etc/issue" ]; then + # lsb_release is *really* slow; try to use /etc/issue first + local issue + IFS="" read issue < /etc/issue + case "$issue" in + Ubuntu*) + distro="Ubuntu"; + ;; + Debian*) + distro="Debian" + ;; + Red\ Hat\ Enterprise*) + distro="RHEL" + ;; + *) + # assume first field is what we want + distro="${issue%% *}"; + ;; + esac + elif $BYOBU_TEST lsb_release >/dev/null 2>&1; then + # If lsb_release is available, use it + local r=$(lsb_release -s -d) + case "$r" in + Ubuntu*) + # Use the -d if an Ubuntu LTS + distro="Ubuntu" + ;; + *) + # But for other distros the description + # is too long, so build from -i and -r + distro=$(lsb_release -s -i) + ;; + esac + elif $BYOBU_TEST sw_vers >/dev/null 2>&1; then + distro="$(sw_vers -productName)" + elif $BYOBU_TEST uname >/dev/null 2>&1; then + distro="$(uname -s)" + else + distro="Byobu" + fi + _RET="$distro" +} + # vi: syntax=sh ts=4 noexpandtab diff --git a/usr/lib/byobu/logo b/usr/lib/byobu/logo index 987ff3c1..cfe9252f 100755 --- a/usr/lib/byobu/logo +++ b/usr/lib/byobu/logo @@ -19,28 +19,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -get_distro() { - _RET= - if [ -n "$DISTRO" ]; then - # Allow manual override of distro in $BYOBU_CONFIG_DIR/status - _RET="$DISTRO" - elif [ -r "/etc/issue" ]; then - # Otherwise, check /etc/issue - _RET=`grep -m1 "^[A-Za-z]" /etc/issue` - elif $BYOBU_TEST lsb_release >/dev/null 2>&1; then - # This can be a very expensive operation, do it only - # if all other methods fail - _RET=`lsb_release -s -a 2>/dev/null` - elif $BYOBU_TEST sw_vers >/dev/null 2>&1; then - _RET=`sw_vers 2>/dev/null` - elif $BYOBU_TEST uname >/dev/null 2>&1; then - _RET=`uname -s` - else - # No idea! - _RET="[B]" - fi -} - __logo_detail() { MARKUP="false" __logo