#!/usr/bin/perl
# @title : Theme info script 0.1.2 revisited
# @author: rab
# @date : 08/04/08
# @commnt: Maybe if people quit forking the hell outta this, it would be easier to maintain
## Configurations
# On = 1. Off = 0
my %display = (
"OS" => 1, # Displays the operating system's name
"KL" => 1, # Displays your kernel version
"DE" => 0, # Displays your desktop environment, if you have one
"WM" => 1, # Displays your window manager
"WMT" => 1, # Displays your window manager's theme
"IC" => 1, # Displays your icon theme, if you have one
"FN" => 1, # Displays your font
"UI" => 1 # Displays your UI theme
);
# The command to execute for taking a screenshot
# Escape ' with a backslash, \'
# Leave blank if you don't want a screenshot taken
#my $screenshot = 'scrot screen-%H-%M-%S.png -e \'mv $f ~/media/screens/\'';
my $screenshot = '';
# The Color to use for the variables, needs to be global for logos.pl
@colors = ( "\e[38;0;33m", "\e[38;1;37m", "\e[m" );
# Debugging
my $debug = 1;
## End of configuration
########################
## Script starts here ##
########################
@distros = ();
require '/home/flo/bin/logos.pl';
my $nocolor = "\e[0m";
my @info = ();
my ($DE,$WM,$theme,$icon,$font,$cscheme) = "";
my $distro = &distro;
## Hash of WMs and the process they run #
my %WMlist = ("Beryl" => "beryl",
"Fluxbox" => "fluxbox",
"Openbox" => "openbox",
"Blackbox" => "blackbox",
"Xfwm4" => "xfwm4",
"Metacity" => "metacity",
"Kwin" => "kwin",
"FVWM" => "fvwm",
"Enlightenment" => "enlightenment",
"IceWM" => "icewm",
"Window Maker" => "wmaker",
"Compiz-Fusion" => "compiz",
"PekWM" => "pekwm",
"Awesome" => "awesome",
"Dwm" => "dwm" );
## Hash of DEs and the process they run ##
my %DElist = ("Gnome" => "gnome-session",
"Xfce4" => "xfce-mcs-manage",
"KDE" => "ksmserver");
## Get Kernel version ##
if( $display{KL} ) {
print "::$colors[0] Finding Kernel version$nocolor\n"
if $debug;
my $kernel = `uname -r`; $kernel =~ s/\s+/ /g;
push @info, "$colors[0]Kernel\t\t\t$colors[1]$kernel$nocolor";
}
## Find running processes ##
print "::$colors[0] Getting processes$nocolor\n"
if $debug;
my $processes = `ps -A | awk {'print \$4'}`;
## Find a Desktop Environment ##
DESKTOP:
goto WINDOWM if !$display{DE};
while(my($DEname,$DEprocess) = each(%DElist)) {
next if $processes !~ /$DEprocess/s;
$DE = $DEname;
print "::$colors[0] Desktop Environment found as $colors[1]$DEname$nocolor\n"
if $debug;
push @info, "$colors[0]Desktop Environment\t$colors[1]$DEname$nocolor";
last;
}
## Find a Window Manager ##
WINDOWM:
goto ICON if !$display{WM};
while(my($WMname,$WMprocess) = each(%WMlist)) {
next if $processes !~ /$WMprocess/sg;
$WM = $WMname;
print "::$colors[0] Window Manager found as $colors[1]$WMname$nocolor\n"
if $debug;
push @info, "$colors[0]Window Manager\t\t$colors[1]$WMname$nocolor";
last;
}
## Find a Window Manager Theme ##
WINDOWMT:
goto ICON if !$display{WMT} || !$display{WM} || $WM eq "";
print "::$colors[0] Finding $WM theme$nocolor\n"
if $debug;
$WM eq "Openbox" && do {
($theme) = fgrep(["$ENV{HOME}/.config/openbox/rc.xml"], ["(.+?)"]);
goto ICON;
};
$WM eq "Beryl" && do {
($theme) = fgrep(["$ENV{HOME}/.emerald/theme/theme.ini"], ["description=(.*?)$/"]);
goto ICON;
};
$WM eq "Metacity" && do {
$theme = `gconftool-2 -g /apps/metacity/general/theme`;
chomp $theme;
goto ICON;
};
$WM eq "Fluxbox" && do {
($theme) = fgrep(["$ENV{HOME}/.fluxbox/init"], ["session.styleFile:\s*/.*?/(.+?)"]);
goto ICON;
};
$WM eq "Blackbox" && do {
($theme) = fgrep(["$ENV{HOME}/.blackboxrc"], ["session.styleFile:\s*/.*?/(.+?)"]);
goto ICON;
};
$WM eq "Xfwm4" && do {
($theme) = fgrep(["$ENV{HOME}/.config/xfce4/mcs_settings/xfwm4.xml"], ["',
'',
'']);
goto PRINT;
};
$DE eq "KDE" && do {
($theme,$cscheme,$icon,$font) = fgrep(["$ENV{HOME}/.kde/share/config/kdeglobals"],
['widgetStyle=(.+?)\s',
'colorScheme=(.+?)\.kcsrc\s',
'Theme=(.+?)\s',
'font=(.+?)\s']);
$font = (split /,/, $font)[0];
goto PRINT;
};
@vars = fgrep(["$ENV{HOME}/.gtkrc-2.0",
"$ENV{HOME}/.gtkrc.mine"],
['include ".*?themes/(.+?)/gtk-[12]\.0/gtkrc',
'.*?gtk-icon-theme-name.*?"(.+?)"',
'.*?gtk-font-name.*?"(.+?)"']);
$theme = $vars[0] ? $vars[0] : $vars[3] ? $vars[3] : "";
$icon = $vars[1] ? $vars[1] : $vars[4] ? $vars[4] : "";
$font = $vars[2] ? $vars[2] : $vars[5] ? $vars[5] : "";
## Lets print this bitch ##
PRINT:
push @info, $colors[0].($DE ? $DE : "GTK")." Theme \t\t$colors[1]".($DE eq "KDE" ? "$theme/$cscheme" : $theme).$nocolor
if $display{UI} && $theme ne "";
push @info, "$colors[0]Icons\t\t\t$colors[1]$icon$nocolor"
if $display{IC} && $icon ne "";
push @info, "$colors[0]Font\t\t\t$colors[1]$font$nocolor"
if $display{FN} && $font ne "";
printf $distro, @info; sleep 3;
exec $screenshot
if $screenshot ne "";
sub fgrep(\@\@) {
my($files,$regexps) = @_;
my @retvals = ();
my $slurp = $/; undef $/;
foreach my $file (@$files) {
next if !(-e $file);
open FILE, "<", $file || die "$colors[0]Error opening $colors[1]'$file', $colors[0]$!$nocolor\n";
$content = ;
close FILE;
foreach my $regexp (@$regexps) {
my $expg = 0; $expg++ while( $regexp =~ /\(.*?\)/g );
my @tmp = $content =~ /$regexp/sg;
push @tmp, "" while( scalar @tmp < $expg );
@retvals = (@retvals,@tmp);
}
}
$/ = $slurp;
@retvals;
}
sub distro {
my $distro = "";
my $slurp = $/; undef $/;
foreach $ops (@distros) {
next if !(-e @$ops[1]);
$fdistro = $distro = @$ops[0];
open FILE, "<", @$ops[1] || die "$colors[0]Error opening $colors[1]'@$ops[1]', $colors[0]$!$nocolor\n";
$content = ;
close FILE;
if( defined @$ops[2] ) {
$content =~ /@$ops[2]/sg;
$fdistro .= " ($1)";
}
chomp $distro; chomp $fdistro;
last;
}
return ""
if $distro eq "";
$/ = $slurp; $distro = lc $distro;
eval "\$distro = \$$distro;";
push @info, "$colors[0]Distro\t\t\t$colors[1]$fdistro$nocolor";
$distro;
}