You can type env to figure out what environments are configured.
The following response was found from this link
XDG_CURRENT_DESKTOP - Tells you what Windows Manager you are using
GDMSESSION - Tells you what option you selected from the lightdm greeter to login.
To use them, go to the terminal and type:
echo $XDG_CURRENT_DESKTOP
(Will output for example 'unity' if you are using Unity)
or
echo $GDMSESSION
(Will output for example 'ubuntu' if you selected ubuntu in the login or 'ubuntu-2d' if you selected that one in the login.)
You have others if you look closer at the output of env like DESKTOP_SESSION and COMPIZ_CONFIG_PROFILE
Since what you are looking for is the name of what Window Manager is in usem the only way I see how to get this is by looking in the process list. To do this there is a command called pgrep ( Wikipedia ). I did the following to get the name since the parameter -l adds the process ID:
pgrep -l compiz |cut -d " " -f2 since the process is running by the same user there is no need to prefix the sudo part. You can then use this to create a script that does an action based on the Window Manager.
To look for other types, just change the word compiz to another like mutter, kwin, etc..
On Ubuntu 12.04 I tested environment variables XDG_CURRENT_DESKTOP and GDMSESSION and got the following results:
KDE
XDG_CURRENT_DESKTOP=
GDMSESSION=kde-plasma
Unity 3d
XDG_CURRENT_DESKTOP=Unity
GDMSESSION=ubuntu
Unity 2d
XDG_CURRENT_DESKTOP=Unity
GDMSESSION=ubuntu-2d
Gnome
XDG_CURRENT_DESKTOP=GNOME
GDMSESSION=gnome-shell
Gnome Classic
XDG_CURRENT_DESKTOP=GNOME
GDMSESSION=gnome-classic
Gnome Classic no effects
XDG_CURRENT_DESKTOP=GNOME
GDMSESSION=gnome-fallback
Other Ubuntu based distributions:
Mint 13 (Cinnamon)
XDG_CURRENT_DESKTOP=GNOME
GDMSESSION=cinnamon
Lubuntu 12.04
XDG_CURRENT_DESKTOP=LXDE
GDMSESSION=Lubuntu