Morten Nilsen wrote:
If I understand correctly, this patch was written for Slackware? If so I
can't take it...what we would want is a script that at least covers most
of the major distros (Debian, Mandriva, Fedora, Ubuntu, Gentoo,
Slackware) and understands how each of them stores X sessions. For
example, Mandriva does not use .desktop files to store sessions - it
keeps entries under /etc/X11/wmsession.d/. This is probably much better
done as a script that determines the system's linux distribution,
obtains the X sessions accordingly, and outputs a session list that can
then be compiled into the configuration at build time.
I see your point..
I'll see what I can do in the scripting department.. at least for a bare
bones script that handles the .desktop way as a start .. people on
systems that actually have different methods would have to pitch in :)
Here's a basic skeleton script.. running it produces (on my system);
E16:starte16:enlightenment.png
Enlightenment:/usr/bin/enlightenment:enlightenment.png
which is pretty much just taken verbatim from the .desktops, only an
icon has been guessed for "Enlightenment" (a file that exists)
There's a ton of improvements one could do, but I'd like to just put
this basic implementation out there for people to start poking at with
sticks :)
--
Morten
:wq
#!/bin/bash
# Session lister originally written by Morten Nilsen <[EMAIL PROTECTED]>
# This code is covered by entrance's license
## Function declarations
function desktop_parse
{
awk -F= '
BEGIN{ type=""; session=""; icon=""; name=""; valid = 0; }
$0=="[Desktop Entry]"{ valid = 1; next; }
$1=="Type"{ type = $2; next; }
$1=="Name"{ name = $2; next; }
$1=="Icon"{ icon = $2; next; }
$1=="Exec"{ session = $2; next; }
$1=="TryExec"{ session = $2; next; }
{ next; }
END{
if(type == "XSession")
printf("%s:%s:%s\n", name, session, icon);
}
' $1
}
function guess_icon
{
if [ "x$1" == "x" ]; then
return;
fi
guess=`basename $1 | tr A-Z a-z`
for icondir in /usr/share/pixmaps /usr/share/entrance/images/sessions; do
for ext in png jpg; do
if [ -f "${icondir}/${guess}.${ext}" ]; then
echo "${guess}.${ext}";
return;
fi
done
done
}
function session_parse
{
name=`echo $1 | awk -F: '{print $1}'`;
session=`echo $1 | awk -F: '{print $2}'`;
icon=`echo $1 | awk -F: '{print $3}'`;
if [ "x$session" == "x" ]; then
return;
fi
# Guess an icon
if [ "x$icon" == "x" ]; then
icon=`guess_icon $name`
if [ "x$icon" == "x" ]; then
icon=`guess_icon $session`
fi
fi
# if no name is given, use lowercased session entry
if [ "x$name" == "x" ]; then
name=`basename $session | tr A-Z a-z`
fi
echo "$name:$session:$icon"
}
## Session list builder
sessions=""
## parse xsession .desktop files
if [ -d /usr/share/xsessions ]; then
for desktop in /usr/share/xsessions/*.desktop; do
sessions="${sessions} `desktop_parse $desktop`";
done
fi
## TODO Implement other parsers here,
## and associated functions above as needed
## Final step, prints out NAME:SESSION:ICON\n
for session in $sessions; do
session_parse $session;
done