* 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
This commit is contained in:
Dustin Kirkland 2013-08-02 17:16:28 -05:00
commit cdb1780181
5 changed files with 55 additions and 62 deletions

3
debian/changelog vendored
View file

@ -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 <kirkland@ubuntu.com> Sun, 28 Jul 2013 19:51:39 -0500

View file

@ -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" <<EOF

View file

@ -28,47 +28,10 @@ __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"
get_distro
DISTRO="$_RET"
fi
[ -n "$DISTRO" ] || return
color bold2; printf "%s" "$DISTRO"; color --
}

View file

@ -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

View file

@ -19,28 +19,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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