Marcelo E. Magallon wrote:
>
> On Wed, Jul 29, 1998 at 12:42:13PM -0400, Shaleh wrote:
>
> > I just recieved a bug report on Enlightenment asking for me to put it in
> > /etc/X11/window-managers. Fairly confident that touching another
> > packages files would be wrong, what is the correct way to get E into
> > this file? Or should my package touch /etc/X11/window-managers?
>
> Several window managers add themselves (afterstep and wmaker, for example),
> and /etc/X11/window-managers belongs to no package. The file is created by
> xbase (wmaker creates the file, too). Last night I was thinking about filing
> a wishlist bug against xbase, basically asking to it to provide a simple
> script, update-window-managers, that would manage that file. Ideally, it
> could:
>
> --add adds a window manager to the bottom of the list
> --default used with --add, adds the wm to the top of the list
> or moves the named windowmanager to the top
> --remove removes a wm from the list
> --ask asks for confirmation on this operations
> (this could be --noask)
>
> the window manager would be just a name (enlightenment) or a full path
> specification (/usr/X11R6/bin/wmaker). In the former case, /usr/X11R6/bin
> would be used as the path.
>
> I was going to write an implementation of this, but I got caught in other
> things... if you want to go ahead, be my guest.
>
> Marcelo
Enclosed is my script. All functionality but the --ask (or noask) is
there. Please send comments/questions/complaints my way. Sorry Marcelo
I did it in Perl (-:
#! /usr/bin/perl
###
#
# written by Shaleh <[EMAIL PROTECTED]>
#
###
unless( @ARGV == 2 ) {
die("Usage: update-windowmanagers {--add|--default|--remove} <wm>\n");
}
if( $ARGV[1] !~ m/^\// ) {
$WM = '/usr/X11R6/bin' . $ARGV[1];
}
else {
$WM = $ARGV[1];
}
if( $ARGV[0] eq '--add' ) {
&add_to_file($WM);
}
elsif( $ARGV[0] eq '--default' ) {
&make_default($WM);
}
elsif( $ARGV[0] eq '--remove' ) {
&rm_from_file($WM);
}
else {
print("$ARGV[0] is an unknown option\n");
die("Usage: update-windowmanagers {--add|--default|--remove} <wm>\n");
}
###
#
# Adds window manager passed to the end of window-managers file
#
###
sub add_to_file {
($wm) = @_;
return unless( &ifexists($wm) eq 'false' );
open(WMFILE, '>>/etc/X11/window-managers') ||
die("Could not open /etc/X11/window-managers for writing\n");
print WMFILE "$wm\n";
close(WMFILE);
}
###
#
# Makes window manager passed the default by putting it first
#
###
sub make_default {
($wm) = @_;
my $found = 0;
if( &ifexists($wm) eq 'true' ) {
&rm_from_file($wm);
}
open(WMFILE, '/etc/X11/window-managers') ||
die("Could not open /etc/X11/window-managers\n");
@WMS = <WMFILE>;
close(WMFILE);
open(WMFILE, '>/etc/X11/window-managers') ||
die("Could not open /etc/X11/window-managers for writing\n");
foreach (@WMS) {
if( m/^\// && $found == 0 ) {
print WMFILE "$wm\n";
$found = 1;
}
print WMFILE;
}
close(WMFILE);
}
###
#
# Removes passed window manager from window-managers file
#
###
sub rm_from_file {
($wm) = @_;
return unless( &ifexists($wm) eq 'true' );
open(WMFILE, '/etc/X11/window-managers') ||
die("Could not open /etc/X11/window-managers\n");
@WMS = <WMFILE>;
close(WMFILE);
open(WMFILE, '>/etc/X11/window-managers') ||
die("Could not open /etc/X11/window-managers for writing\n");
foreach (@WMS) {
print WMFILE unless( m/$wm/ );
}
}
###
#
# returns 'true' if window manager exists in the file, 'false' otherwise
#
###
sub ifexists {
($wm) = @_;
open(WMFILE, '/etc/X11/window-managers') ||
die("Could not open /etc/X11/window-managers\n");
@WMS = <WMFILE>;
close WMFILE;
foreach (@WMS) {
unless( m/^#/ ) {
if( m/$wm/ ) {
return 'true';
}
}
}
return 'false';
}