#!/usr/bin/perl # # my version 0.2 ? ( dispite all of the other forks ) # # # + Fri Dec 22 10:15:09 PST 2006 # # + Added 6 more WM support # + Created a function that for opening a file and # grabbing something out of it # # - ( $first_reg, $second_$reg) = fopen_reg( \[ "file path", "if more"], \[ [ "reg exp", "if more" ] ] ); # - It returns an array of the matched strings # - Arrays must be passed as a reference to the actual array # - If you can improve to it, be my guest # # # Basically just one big config array %sh = ( kernel => { f => 1, i => `uname -r` }, OS => { f => 1, i => `cat /etc/arch-release` }, wm => { f => 1, wmtheme => undef, wmname => undef }, Gtk => { f => 1, Gtktheme => undef, Gtkfont => undef, Gtkicons => undef, Gtkfiles => [ "$ENV{HOME}/.gtkrc-2.0", "$ENV{HOME}/.gtkrc.mine" ], Gtkregex => [ [ "include \"/.+/(?:\\.themes|themes)/(.+)/gtk-(1|2)\\.0/gtkrc\"", "gtk-theme-name\\s*=\\s*\"(.+)\"" #Gtk Themes ], [ "gtk-icon-theme-name\\s*=\\s*\"(.+)\"" #Gtk Icon themes ], [ "gtk-font-name\\s*=\\s*\"(.+)\"" #Gtk Font name ] ] }, Qt => { f => 0, Qtfont => undef, Qttheme => undef, Qticons => undef, Qtfiles => [ "$ENV{HOME}/.kde/share/config/kdeglobals" ], Qtregex => [ [ "Theme=(.+)" ], [ "widgetStyle=(.+)" ], [ "font=(.+)" ] ] }, de => { f => 1, is => 0, name => undef, theme => undef, font => undef, icon => undef } ); %de = ( Gnome => "gnome-session", Xfce4 => "xfdesktop", Kde => "kdesktop" ); @wm = qw(Ratpoison Fluxbox Openbox Blackbox Xfwm4 E16 Metacity Kwin Pekwm Pwm Icewm Ion3 WMii); # %de goes by the name of the DE # and the 'id' you can find it in # the PS list... $quiet = 1; # Prints little debugging messages if set to 0; $tk = ( $sh{Gtk}{f} ? "Gtk" : "Qt" ); chomp $sh{OS}{i}; chomp $sh{kernel}{i}; parsePS("de"); if( !$sh{de}{is} ) { print "No DE found, not running one?..\n" unless $quiet; ( $sh{$tk}{"${tk}theme"}, $sh{$tk}{"${tk}icon"}, $sh{$tk}{"${tk}font"} ) = fopen_reg(\$sh{$tk}{"${tk}files"}, \$sh{$tk}{"${tk}regex"}); ## Processes First parsePS("wm"); ## Couldn't find a WM in PS print "No WM found, yours isn't on the list?...\n" if ( !$quiet && !$sh{wm}{wmname} ); } &printlogo; sub printlogo { my @temp; push @temp, "OS: $sh{OS}{i}" unless !$sh{OS}{f}; push @temp, "Kernel: $sh{kernel}{i}" unless !$sh{kernel}{f}; if( $sh{de}{is} && $sh{de}{f} ) { push @temp, "DE: $sh{de}{name}"; push @temp, "$sh{de}{name} Theme: $sh{de}{theme}" unless !defined $sh{de}{theme}; push @temp, "$sh{de}{name} Icons: $sh{de}{icon}" unless !defined $sh{de}{icon}; push @temp, "$sh{de}{name} Font: $sh{de}{font}" unless !defined $sh{de}{font}; } elsif( $sh{$tk}{f} ) { push @temp, "$tk Theme: ".$sh{$tk}{"${tk}theme"} unless !defined $sh{$tk}{"${tk}theme"}; push @temp, "$tk Icons: ".$sh{$tk}{"${tk}icon"} unless !defined $sh{$tk}{"${tk}icon"}; push @temp, "$tk Font: ".$sh{$tk}{"${tk}font"} unless !defined $sh{$tk}{"${tk}font"}; } push @temp, "WM: $sh{wm}{wmname}" unless (!defined $sh{wm}{wmname} || !$sh{wm}{f}); push @temp, "$sh{wm}{wmname} Theme: $sh{wm}{wmtheme}" unless (!defined $sh{wm}{wmtheme} || !$sh{wm}{f}); for( $x = 0; $x < @temp; $x++) { print $temp[$x]."\n"; } } sub parsePS { $_ = shift; my @psl = split /\n/, `ps -A | awk {'print \$4'}`; SWITCH: { /wm/ && do { for( my $x = 0; $x < @wm; $x++ ) { for( my $y = 0; $y < @psl; $y++ ) { print "Testing '$psl[$y]' with '$wm[$x]'\n" unless $quiet; if( $psl[$y] =~ /^$wm[$x]$/i ) { print "WM found as $wm[$x]\n" unless $quiet; $sh{wm}{wmname} = $wm[$x]; &wmtheme; last; } } $sh{wm}{wmname} && last; } last SWITCH; }; /de/ && do { while(($de, $deid) = each %de) { for( my $x = 0; $x < @psl; $x++ ) { print "Testing '$psl[$x]' with '$deid'\n" unless $quiet; if( $psl[$x] eq $deid ) { print "DE found as $de\n" unless $quiet; $sh{de}{is} = 1; $sh{de}{name} = $de; ($sh{de}{theme}, $sh{de}{icon}, $sh{de}{font}) = &deinfo; last; } } $sh{de}{is} && last; } parsePS("wm"); last SWITCH; }; } } sub fopen_reg { my ( $files, $regexp ) = @_; my @ret; for( my $file = 0; $file < @$$files; $file++ ) { print "Opening $$files->[$file]\n" unless $quiet; open FILE, "<", $$files->[$file] || die "$!\nFile: $$files->[$file]\n"; while( ) { for( my $y = 0; $y < @$$regexp; $y++) { my $regex = $$$regexp[$y]; for( $z = 0; $z < @$regex; $z++ ) { print "\tSearching for $regex->[$z]\n" unless $quiet; if( /$regex->[$z]/ ) { $ret[$y] = $1; print "Found a value \"$1\"\n" unless $quiet; pop @$regex, $regex->[$z]; } } } } close FILE; } return @ret; } sub wmtheme { $_ = $sh{wm}{wmname}; SWITCH: { /openbox/i && do { ($sh{wm}{wmtheme}) = fopen_reg( \[ "$ENV{HOME}/.config/openbox/rc.xml" ], \[ ["(.+)"] ] ); last SWITCH; }; /metacity/i && do { $sh{wm}{wmtheme} = `gconftool-2 -g /apps/metacity/general/theme`; last SWITCH; }; /fluxbox/i && do { ($sh{wm}{wmtheme}) = fopen_reg( \[ "$ENV{HOME}/.fluxbox/init"], \[ [ "session\\.styleFile:\\s*/.+/(.+)/?\$" ] ] ); last SWITCH; }; /blackbox/i && do { ($sh{wm}{wmtheme}) = fopen_reg( \[ "$ENV{HOME}/.blackboxrc" ], \[ [ "session\\.styleFile:\\s*/.+/(.+)/?\$" ] ] ); last SWITCH; }; /xfwm/i && do { ($sh{wm}{wmtheme}) = fopen_reg( \[ "$ENV{HOME}/.config/xfce4/mcs_settings/xfwm4.xml" ], \[ [ "