From 3e60b263a0c204fb71433be3fde12c61ba22c93a Mon Sep 17 00:00:00 2001 From: inxi-svn Date: Sat, 21 May 2011 22:19:36 +0000 Subject: [PATCH] refactored desktop detections to avoid repeated code --- inxi | 78 +++++++++++++++++++++++++++--------------------------------- 1 file changed, 35 insertions(+), 43 deletions(-) diff --git a/inxi b/inxi index 8157b9d..a8cf26a 100755 --- a/inxi +++ b/inxi @@ -2551,10 +2551,7 @@ detect_desktop_environment() # note, GNOME_DESKTOP_SESSION_ID is deprecated so we'll see how that works out # https://bugzilla.gnome.org/show_bug.cgi?id=542880 if [[ -n $GNOME_DESKTOP_SESSION_ID ]]; then - version=$( gnome-about --version 2>/dev/null | gawk '{print $3}' ) - if [[ -n $version ]];then - version=" $version" - fi + version=$( get_de_version 'gnome-about' 'gnome' '3' ) if [[ $B_EXTRA_DATA == 'true' ]];then # this is a hack, and has to be changed with every toolkit version change toolkit=$( pkg-config --modversion gtk+-3.0 2>/dev/null ) @@ -2608,84 +2605,61 @@ detect_desktop_environment() fi fi desktop_environment="KDE $version" - # note: fluxbox has a positive PID for blackbox, so I think most desktops can be detected - # with some work + # now that the primary ones have been handled, next is to find the ones with unique + # xprop detections possible else ps_aux="$( ps aux )" if [[ -n $( type -p xprop ) ]];then xprop_root="$( xprop -root 2>/dev/null )" + # String: "This is xfdesktop version 4.2.12" if [[ -n $( grep -Eis '\"xfce4\"' <<< "$xprop_root" ) ]];then - version=$( xfdesktop --version 2>/dev/null | grep -Eosi 'xfdesktop version [0-9\.]+' | gawk '{print $3}' ) - if [[ -n $version ]];then - version=" $version" - else + version=$( get_de_version 'xfdesktop' 'xfdesktop version' '5' ) + if [[ -z $version ]];then version="4" fi desktop_environment="Xfce${version}" + # when 5 is released, the string may need updating elif [[ -n $( grep -is '\"xfce5\"' <<< "$xprop_root" ) ]];then - version=$( xfdesktop --version 2>/dev/null | grep -Eosi 'xfdesktop version [0-9\.]+' | gawk '{print $3}' ) - if [[ -n $version ]];then - version=" $version" - else + version=$( get_de_version 'xfdesktop' 'xfdesktop version' '5' ) + if [[ -z $version ]];then version="5" fi desktop_environment="Xfce${version}" elif [[ -n $( grep -is 'BLACKBOX_PID' <<< "$xprop_root" ) ]];then if [[ -n $( grep -is 'fluxbox' <<< "$ps_aux" | grep -v 'grep' ) ]];then - version=$( fluxbox --version 2>/dev/null | grep -Esi 'fluxbox ([[:digit:]]|GIT)' | gawk '{print $2}' ) - if [[ -n $version ]];then - version=" $version" - fi + version=$( get_de_version 'fluxbox' 'fluxbox ([[:digit:]]|GIT)' '2' ) desktop_environment="Fluxbox${version}" else desktop_environment='Blackbox' fi elif [[ -n $( grep -is 'OPENBOX_PID' <<< "$xprop_root" ) ]];then - version=$( openbox --version 2>/dev/null | grep -Esi 'openbox ([[:digit:]]|GIT)' | gawk '{print $2}' ) - if [[ -n $version ]];then - version=" $version" - fi + version=$( get_de_version 'openbox' 'openbox ([[:digit:]]|GIT)' '2' ) if [[ -n $( grep -is 'lxde' <<< "$ps_aux" | grep -v 'grep' ) ]];then if [[ -n $version ]];then - version=" (Openbox $version)" + version=" (Openbox$version)" fi desktop_environment="LXDE${version}" else desktop_environment="Openbox${version}" fi elif [[ -n $( grep -is 'ICEWM' <<< "$xprop_root" ) ]];then - version=$( icewm --version 2>/dev/null | grep -Esi 'iceWM ([[:digit:]]|GIT)' | gawk '{gsub(/,/, ""); print $2}' ) - if [[ -n $version ]];then - version=" $version" - fi + version=$( get_de_version 'icewm' 'icewm ([[:digit:]]|GIT)' '2' ) desktop_environment="IceWM${version}" fi fi # a few manual hacks for things that don't id with xprop, these are just good guesses if [[ -z $desktop_environment ]];then if [[ -n $( grep -is 'fvwm-crystal' <<< "$ps_aux" | grep -v 'grep' ) ]];then - version=$( fvwm --version 2>/dev/null | grep -Esi 'fvwm ([[:digit:]]|GIT)' | gawk '{print $2}' ) - if [[ -n $version ]];then - version=" $version" - fi + version=$( get_de_version 'fvwm' 'fvwm ([[:digit:]]|GIT)' '2' ) desktop_environment="FVWM-Crystal${version}" elif [[ -n $( grep -is 'fvwm' <<< "$ps_aux" | grep -v 'grep' ) ]];then - version=$( fvwm --version 2>/dev/null | grep -Esi 'fvwm ([[:digit:]]|GIT)' | gawk '{print $2}' ) - if [[ -n $version ]];then - version=" $version" - fi + version=$( get_de_version 'fvwm' 'fvwm ([[:digit:]]|GIT)' '2' ) desktop_environment="FVWM${version}" elif [[ -n $( grep -is 'pekwm' <<< "$ps_aux" | grep -v 'grep' ) ]];then - version=$( pekwm --version 2>/dev/null | grep -Esi 'pekwm.*([[:digit:]]|GIT)' | gawk '{print $3}' ) - if [[ -n $version ]];then - version=" $version" - fi + version=$( get_de_version 'pekwm' 'pekwm.*([[:digit:]]|GIT)' '3' ) desktop_environment="pekwm${version}" elif [[ -n $( grep -is 'awesome' <<< "$ps_aux" | grep -v 'grep' ) ]];then - version=$( awesome --version 2>/dev/null | grep -Esi 'awesome' | gawk '{print $2}' ) - if [[ -n $version ]];then - version=" $version" - fi + version=$( get_de_version 'awesome' 'awesome' '2' ) desktop_environment="Awesome${version}" fi fi @@ -2694,6 +2668,24 @@ detect_desktop_environment() eval $LOGFE } +# args: $1 - desktop command for --version; $2 - search string; $3 - gawk print number +get_de_version() +{ + local version='' + + version=$( $1 --version 2>/dev/null | gawk ' + BEGIN { + IGNORECASE=1 + } + /'$2'/{ + print $'$3' + }' ) + if [[ -n $version ]];then + version=" $version" + fi + + echo $version +} # for more on distro id, please reference this python thread: http://bugs.python.org/issue1322 ## return distro name/id if found get_distro_data()