mirror of
https://github.com/smxi/inxi.git
synced 2024-11-17 00:31:19 +00:00
refactored desktop detections to avoid repeated code
This commit is contained in:
parent
7f928d583f
commit
3e60b263a0
78
inxi
78
inxi
|
@ -2551,10 +2551,7 @@ detect_desktop_environment()
|
||||||
# note, GNOME_DESKTOP_SESSION_ID is deprecated so we'll see how that works out
|
# note, GNOME_DESKTOP_SESSION_ID is deprecated so we'll see how that works out
|
||||||
# https://bugzilla.gnome.org/show_bug.cgi?id=542880
|
# https://bugzilla.gnome.org/show_bug.cgi?id=542880
|
||||||
if [[ -n $GNOME_DESKTOP_SESSION_ID ]]; then
|
if [[ -n $GNOME_DESKTOP_SESSION_ID ]]; then
|
||||||
version=$( gnome-about --version 2>/dev/null | gawk '{print $3}' )
|
version=$( get_de_version 'gnome-about' 'gnome' '3' )
|
||||||
if [[ -n $version ]];then
|
|
||||||
version=" $version"
|
|
||||||
fi
|
|
||||||
if [[ $B_EXTRA_DATA == 'true' ]];then
|
if [[ $B_EXTRA_DATA == 'true' ]];then
|
||||||
# this is a hack, and has to be changed with every toolkit version change
|
# this is a hack, and has to be changed with every toolkit version change
|
||||||
toolkit=$( pkg-config --modversion gtk+-3.0 2>/dev/null )
|
toolkit=$( pkg-config --modversion gtk+-3.0 2>/dev/null )
|
||||||
|
@ -2608,84 +2605,61 @@ detect_desktop_environment()
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
desktop_environment="KDE $version"
|
desktop_environment="KDE $version"
|
||||||
# note: fluxbox has a positive PID for blackbox, so I think most desktops can be detected
|
# now that the primary ones have been handled, next is to find the ones with unique
|
||||||
# with some work
|
# xprop detections possible
|
||||||
else
|
else
|
||||||
ps_aux="$( ps aux )"
|
ps_aux="$( ps aux )"
|
||||||
if [[ -n $( type -p xprop ) ]];then
|
if [[ -n $( type -p xprop ) ]];then
|
||||||
xprop_root="$( xprop -root 2>/dev/null )"
|
xprop_root="$( xprop -root 2>/dev/null )"
|
||||||
|
# String: "This is xfdesktop version 4.2.12"
|
||||||
if [[ -n $( grep -Eis '\"xfce4\"' <<< "$xprop_root" ) ]];then
|
if [[ -n $( grep -Eis '\"xfce4\"' <<< "$xprop_root" ) ]];then
|
||||||
version=$( xfdesktop --version 2>/dev/null | grep -Eosi 'xfdesktop version [0-9\.]+' | gawk '{print $3}' )
|
version=$( get_de_version 'xfdesktop' 'xfdesktop version' '5' )
|
||||||
if [[ -n $version ]];then
|
if [[ -z $version ]];then
|
||||||
version=" $version"
|
|
||||||
else
|
|
||||||
version="4"
|
version="4"
|
||||||
fi
|
fi
|
||||||
desktop_environment="Xfce${version}"
|
desktop_environment="Xfce${version}"
|
||||||
|
# when 5 is released, the string may need updating
|
||||||
elif [[ -n $( grep -is '\"xfce5\"' <<< "$xprop_root" ) ]];then
|
elif [[ -n $( grep -is '\"xfce5\"' <<< "$xprop_root" ) ]];then
|
||||||
version=$( xfdesktop --version 2>/dev/null | grep -Eosi 'xfdesktop version [0-9\.]+' | gawk '{print $3}' )
|
version=$( get_de_version 'xfdesktop' 'xfdesktop version' '5' )
|
||||||
if [[ -n $version ]];then
|
if [[ -z $version ]];then
|
||||||
version=" $version"
|
|
||||||
else
|
|
||||||
version="5"
|
version="5"
|
||||||
fi
|
fi
|
||||||
desktop_environment="Xfce${version}"
|
desktop_environment="Xfce${version}"
|
||||||
elif [[ -n $( grep -is 'BLACKBOX_PID' <<< "$xprop_root" ) ]];then
|
elif [[ -n $( grep -is 'BLACKBOX_PID' <<< "$xprop_root" ) ]];then
|
||||||
if [[ -n $( grep -is 'fluxbox' <<< "$ps_aux" | grep -v 'grep' ) ]];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}' )
|
version=$( get_de_version 'fluxbox' 'fluxbox ([[:digit:]]|GIT)' '2' )
|
||||||
if [[ -n $version ]];then
|
|
||||||
version=" $version"
|
|
||||||
fi
|
|
||||||
desktop_environment="Fluxbox${version}"
|
desktop_environment="Fluxbox${version}"
|
||||||
else
|
else
|
||||||
desktop_environment='Blackbox'
|
desktop_environment='Blackbox'
|
||||||
fi
|
fi
|
||||||
elif [[ -n $( grep -is 'OPENBOX_PID' <<< "$xprop_root" ) ]];then
|
elif [[ -n $( grep -is 'OPENBOX_PID' <<< "$xprop_root" ) ]];then
|
||||||
version=$( openbox --version 2>/dev/null | grep -Esi 'openbox ([[:digit:]]|GIT)' | gawk '{print $2}' )
|
version=$( get_de_version 'openbox' 'openbox ([[:digit:]]|GIT)' '2' )
|
||||||
if [[ -n $version ]];then
|
|
||||||
version=" $version"
|
|
||||||
fi
|
|
||||||
if [[ -n $( grep -is 'lxde' <<< "$ps_aux" | grep -v 'grep' ) ]];then
|
if [[ -n $( grep -is 'lxde' <<< "$ps_aux" | grep -v 'grep' ) ]];then
|
||||||
if [[ -n $version ]];then
|
if [[ -n $version ]];then
|
||||||
version=" (Openbox $version)"
|
version=" (Openbox$version)"
|
||||||
fi
|
fi
|
||||||
desktop_environment="LXDE${version}"
|
desktop_environment="LXDE${version}"
|
||||||
else
|
else
|
||||||
desktop_environment="Openbox${version}"
|
desktop_environment="Openbox${version}"
|
||||||
fi
|
fi
|
||||||
elif [[ -n $( grep -is 'ICEWM' <<< "$xprop_root" ) ]];then
|
elif [[ -n $( grep -is 'ICEWM' <<< "$xprop_root" ) ]];then
|
||||||
version=$( icewm --version 2>/dev/null | grep -Esi 'iceWM ([[:digit:]]|GIT)' | gawk '{gsub(/,/, ""); print $2}' )
|
version=$( get_de_version 'icewm' 'icewm ([[:digit:]]|GIT)' '2' )
|
||||||
if [[ -n $version ]];then
|
|
||||||
version=" $version"
|
|
||||||
fi
|
|
||||||
desktop_environment="IceWM${version}"
|
desktop_environment="IceWM${version}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
# a few manual hacks for things that don't id with xprop, these are just good guesses
|
# a few manual hacks for things that don't id with xprop, these are just good guesses
|
||||||
if [[ -z $desktop_environment ]];then
|
if [[ -z $desktop_environment ]];then
|
||||||
if [[ -n $( grep -is 'fvwm-crystal' <<< "$ps_aux" | grep -v 'grep' ) ]];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}' )
|
version=$( get_de_version 'fvwm' 'fvwm ([[:digit:]]|GIT)' '2' )
|
||||||
if [[ -n $version ]];then
|
|
||||||
version=" $version"
|
|
||||||
fi
|
|
||||||
desktop_environment="FVWM-Crystal${version}"
|
desktop_environment="FVWM-Crystal${version}"
|
||||||
elif [[ -n $( grep -is 'fvwm' <<< "$ps_aux" | grep -v 'grep' ) ]];then
|
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}' )
|
version=$( get_de_version 'fvwm' 'fvwm ([[:digit:]]|GIT)' '2' )
|
||||||
if [[ -n $version ]];then
|
|
||||||
version=" $version"
|
|
||||||
fi
|
|
||||||
desktop_environment="FVWM${version}"
|
desktop_environment="FVWM${version}"
|
||||||
elif [[ -n $( grep -is 'pekwm' <<< "$ps_aux" | grep -v 'grep' ) ]];then
|
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}' )
|
version=$( get_de_version 'pekwm' 'pekwm.*([[:digit:]]|GIT)' '3' )
|
||||||
if [[ -n $version ]];then
|
|
||||||
version=" $version"
|
|
||||||
fi
|
|
||||||
desktop_environment="pekwm${version}"
|
desktop_environment="pekwm${version}"
|
||||||
elif [[ -n $( grep -is 'awesome' <<< "$ps_aux" | grep -v 'grep' ) ]];then
|
elif [[ -n $( grep -is 'awesome' <<< "$ps_aux" | grep -v 'grep' ) ]];then
|
||||||
version=$( awesome --version 2>/dev/null | grep -Esi 'awesome' | gawk '{print $2}' )
|
version=$( get_de_version 'awesome' 'awesome' '2' )
|
||||||
if [[ -n $version ]];then
|
|
||||||
version=" $version"
|
|
||||||
fi
|
|
||||||
desktop_environment="Awesome${version}"
|
desktop_environment="Awesome${version}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -2694,6 +2668,24 @@ detect_desktop_environment()
|
||||||
eval $LOGFE
|
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
|
# for more on distro id, please reference this python thread: http://bugs.python.org/issue1322
|
||||||
## return distro name/id if found
|
## return distro name/id if found
|
||||||
get_distro_data()
|
get_distro_data()
|
||||||
|
|
Loading…
Reference in a new issue