SHARE
TWEET

binarycodes

a guest Aug 26th, 2008 568 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl
  2. #
  3. # @title : Theme info script 0.1.2 revisited
  4. # @author: rab
  5. # @date  : 08/04/08
  6. # @commnt: Maybe if people quit forking the hell outta this, it would be easier to maintain
  7.  
  8. ## Configurations
  9. # On = 1. Off = 0
  10. my %display = (
  11.                 "OS"        => 1, # Displays the operating system's name
  12.                 "KL"        => 1, # Displays your kernel version
  13.                 "DE"        => 0, # Displays your desktop environment, if you have one
  14.                 "WM"        => 1, # Displays your window manager
  15.                 "WMT"       => 1, # Displays your window manager's theme
  16.                 "IC"        => 1, # Displays your icon theme, if you have one
  17.                 "FN"        => 1, # Displays your font
  18.                 "UI"        => 1  # Displays your UI theme
  19.               );
  20.  
  21. # The command to execute for taking a screenshot
  22. # Escape ' with a backslash, \'
  23. # Leave blank if you don't want a screenshot taken
  24. #my $screenshot = 'scrot screen-%H-%M-%S.png -e \'mv $f ~/media/screens/\'';
  25. my $screenshot = '';
  26.  
  27. # The Color to use for the variables, needs to be global for logos.pl
  28. @colors = ( "\e[38;0;33m", "\e[38;1;37m", "\e[m" );
  29.  
  30. # Debugging
  31. my $debug = 1;
  32. ## End of configuration
  33.  
  34. ########################
  35. ## Script starts here ##
  36. ########################
  37. @distros = ();
  38. require '/home/sujoy/bin/logos.pl';
  39.  
  40. my $nocolor = "\e[0m";
  41. my @info = ();
  42. my ($DE,$WM,$theme,$icon,$font,$cscheme) = "";
  43. my $distro = &distro;
  44.  
  45. ## Hash of WMs and the process they run #
  46. my %WMlist = ("Beryl"           => "beryl",
  47.               "Fluxbox"         => "fluxbox",
  48.               "Openbox"         => "openbox",
  49.               "Blackbox"        => "blackbox",
  50.               "Xfwm4"           => "xfwm4",
  51.               "Metacity"        => "metacity",
  52.               "Kwin"            => "kwin",
  53.               "FVWM"            => "fvwm",
  54.               "Enlightenment"   => "enlightenment",
  55.               "IceWM"           => "icewm",
  56.               "Window Maker"    => "wmaker",
  57.               "Compiz-Fusion"   => "compiz",
  58.               "PekWM"           => "pekwm",
  59.               "Awesome"         => "awesome",
  60.               "Dwm"             => "dwm" );
  61.  
  62. ## Hash of DEs and the process they run ##    
  63. my %DElist = ("Gnome"   => "gnome-session",
  64.               "Xfce4"   => "xfce-mcs-manage",
  65.               "KDE"     => "ksmserver");
  66.  
  67. ## Get Kernel version ##
  68. if( $display{KL} ) {
  69.     print "::$colors[0] Finding Kernel version$nocolor\n"
  70.         if $debug;
  71.  
  72.     my $kernel = `uname -r`; $kernel =~ s/\s+/ /g;
  73.     push @info, "$colors[0]Kernel\t\t\t$colors[1]$kernel$nocolor";
  74. }
  75.  
  76. ## Find running processes ##
  77. print "::$colors[0] Getting processes$nocolor\n"
  78.     if $debug;
  79. my $processes = `ps -A | awk {'print \$4'}`;
  80.  
  81.  
  82. ## Find a Desktop Environment ##
  83. DESKTOP:
  84. goto WINDOWM if !$display{DE};
  85. while(my($DEname,$DEprocess) = each(%DElist)) {
  86.     next if $processes !~ /$DEprocess/s;
  87.  
  88.     $DE = $DEname;
  89.     print "::$colors[0] Desktop Environment found as $colors[1]$DEname$nocolor\n"
  90.         if $debug;
  91.     push @info, "$colors[0]Desktop Environment\t$colors[1]$DEname$nocolor";
  92.     last;
  93. }
  94.  
  95. ## Find a Window Manager ##
  96. WINDOWM:
  97. goto ICON if !$display{WM};
  98. while(my($WMname,$WMprocess) = each(%WMlist)) {
  99.     next if $processes !~ /$WMprocess/sg;
  100.  
  101.     $WM = $WMname;
  102.     print "::$colors[0] Window Manager found as $colors[1]$WMname$nocolor\n"
  103.         if $debug;
  104.     push @info, "$colors[0]Window Manager\t\t$colors[1]$WMname$nocolor";
  105.     last;
  106. }
  107.  
  108. ## Find a Window Manager Theme ##
  109. WINDOWMT:
  110. goto ICON if !$display{WMT} || !$display{WM} || $WM eq "";
  111. print "::$colors[0] Finding $WM theme$nocolor\n"
  112.     if $debug;
  113.  
  114. $WM eq "Openbox" && do {
  115.     ($theme) = fgrep(["$ENV{HOME}/.config/openbox/rc.xml"], ["<name>(.+?)</name>"]);
  116.     goto ICON;
  117. };
  118.  
  119. $WM eq "Beryl" && do {
  120.     ($theme) = fgrep(["$ENV{HOME}/.emerald/theme/theme.ini"], ["description=(.*?)$/"]);
  121.     goto ICON;
  122. };
  123.  
  124. $WM eq "Metacity" && do {
  125.     $theme = `gconftool-2 -g /apps/metacity/general/theme`;
  126.     chomp $theme;
  127.     goto ICON;
  128. };
  129.  
  130. $WM eq "Fluxbox" && do {
  131.     ($theme) = fgrep(["$ENV{HOME}/.fluxbox/init"], ["session.styleFile:\s*/.*?/(.+?)"]);
  132.     goto ICON;
  133. };
  134.  
  135. $WM eq "Blackbox" && do {
  136.     ($theme) = fgrep(["$ENV{HOME}/.blackboxrc"], ["session.styleFile:\s*/.*?/(.+?)"]);
  137.     goto ICON;
  138. };
  139.  
  140. $WM eq "Xfwm4" && do {
  141.     ($theme) = fgrep(["$ENV{HOME}/.config/xfce4/mcs_settings/xfwm4.xml"], ["<option name=\"Xfwm/ThemeName\" type=\"string\" value=\"(.+?)\"/>"]);
  142.     goto ICON;
  143. };
  144.  
  145. $WM eq "Kwin" && do {
  146.     ($theme) = fgrep(["$ENV{HOME}/.kde/share/config/kwinrc"], ['PluginLib=kwin[34]_(.+?)\s']);
  147.     goto ICON;
  148. };
  149.  
  150. $WM eq "Enlightenment" && do {
  151.     my $remote = `enlightenment_remote -theme-get theme`;
  152.     ($theme) = $remote =~ /FILE="(.+?)\\.edj"/sg;
  153.     goto ICON;
  154. };
  155.  
  156. $WM eq "IceWM" && do {
  157.     ($theme) = fgrep(["$ENV{HOME}/.icewm/theme"], ["Theme=\"(.+?)/.*?\\.theme"]);
  158.     goto ICON;
  159. };
  160.  
  161. $WM eq "PekWM" && do {
  162.     ($theme) = fgrep(["$ENV{HOME}/.pekwm/config"], ["Theme.*?/(.*?)"]);
  163.     goto ICON;
  164. };
  165.  
  166. $WM eq "Dwm" && do {
  167.     undef $theme; ## Unless you want to grab some values from the binary?
  168.     goto ICON;
  169. };
  170.  
  171. $WM eq "Awesome" && do {
  172.     undef $theme;
  173.     goto ICON;
  174. };
  175.  
  176. ICON:
  177. if( $theme ne "" ) {
  178.     print "::$colors[0] $WM Theme found as $colors[1]$theme$nocolor\n"
  179.         if $debug;
  180.     push @info, "$colors[0]$WM Theme $colors[1]\t\t$theme$nocolor";
  181. }
  182.  
  183. $DE eq "Gnome" && do {
  184.     $icon = `gconftool-2 -g /desktop/gnome/interface/icon_theme`;
  185.     $font = `gconftool-2 -g /desktop/gnome/interface/font_name`;
  186.     $theme = `gconftool-2 -g /desktop/gnome/interface/gtk_theme`;
  187.     chomp $icon; chomp $font; chomp $theme;
  188.     goto PRINT;
  189. };
  190.  
  191. $DE eq "Xfce4" && do {
  192.     ($icon,$font,$theme) = fgrep(["$ENV{HOME}/.config/xfce4/mcs_settings/gtk.xml"],
  193.                              ['<option name="Net/IconThemeName" type="string" value="(.+?)"/>',
  194.                               '<option name="Gtk/FontName" type="string" value="(.+?)"/>',
  195.                               '<option name="Net/ThemeName" type="string" value="(.+?)"/>']);
  196.     goto PRINT;
  197. };
  198.  
  199. $DE eq "KDE" && do {
  200.     ($theme,$cscheme,$icon,$font) = fgrep(["$ENV{HOME}/.kde/share/config/kdeglobals"],
  201.                                       ['widgetStyle=(.+?)\s',
  202.                                        'colorScheme=(.+?)\.kcsrc\s',
  203.                                        'Theme=(.+?)\s',
  204.                                        'font=(.+?)\s']);
  205.     $font = (split /,/, $font)[0];
  206.     goto PRINT;
  207. };
  208.  
  209. @vars = fgrep(["$ENV{HOME}/.gtkrc-2.0",
  210.                "$ENV{HOME}/.gtkrc.mine"],
  211.               ['include ".*?themes/(.+?)/gtk-[12]\.0/gtkrc',
  212.                '.*?gtk-icon-theme-name.*?"(.+?)"',
  213.                '.*?gtk-font-name.*?"(.+?)"']);
  214.  
  215. $theme = $vars[0] ? $vars[0] : $vars[3] ? $vars[3] : "";
  216. $icon  = $vars[1] ? $vars[1] : $vars[4] ? $vars[4] : "";
  217. $font  = $vars[2] ? $vars[2] : $vars[5] ? $vars[5] : "";
  218.  
  219. ## Lets print this bitch ##
  220. PRINT:
  221. push @info, $colors[0].($DE ? $DE : "GTK")." Theme \t\t$colors[1]".($DE eq "KDE" ? "$theme/$cscheme" : $theme).$nocolor
  222.     if $display{UI} && $theme ne "";
  223.  
  224. push @info, "$colors[0]Icons\t\t\t$colors[1]$icon$nocolor"
  225.     if $display{IC} && $icon ne "";
  226.  
  227. push @info, "$colors[0]Font\t\t\t$colors[1]$font$nocolor"
  228.     if $display{FN} && $font ne "";
  229.  
  230. printf $distro, @info; sleep 3;
  231. exec $screenshot
  232.     if $screenshot ne "";
  233.  
  234. sub fgrep(\@\@) {
  235.     my($files,$regexps) = @_;
  236.     my @retvals = ();
  237.     my $slurp = $/; undef $/;
  238.  
  239.     foreach my $file (@$files) {
  240.         next if !(-e $file);
  241.  
  242.         open FILE, "<", $file || die "$colors[0]Error opening $colors[1]'$file', $colors[0]$!$nocolor\n";
  243.         $content = <FILE>;
  244.         close FILE;
  245.  
  246.         foreach my $regexp (@$regexps) {
  247.             my $expg = 0; $expg++ while( $regexp =~ /\(.*?\)/g );
  248.             my @tmp = $content =~ /$regexp/sg;
  249.             push @tmp, "" while( scalar @tmp < $expg );
  250.             @retvals = (@retvals,@tmp);
  251.         }
  252.     }
  253.  
  254.     $/ = $slurp;
  255.     @retvals;
  256. }
  257.  
  258. sub distro {
  259.     my $distro = "";
  260.     my $slurp = $/; undef $/;
  261.  
  262.     foreach $ops (@distros) {
  263.         next if !(-e @$ops[1]);
  264.  
  265.         $fdistro = $distro = @$ops[0];
  266.         open FILE, "<", @$ops[1] || die "$colors[0]Error opening $colors[1]'@$ops[1]', $colors[0]$!$nocolor\n";
  267.         $content = <FILE>;
  268.         close FILE;
  269.        
  270.         if( defined @$ops[2] ) {
  271.             $content =~ /@$ops[2]/sg;
  272.             $fdistro .= "  ($1)";
  273.         }
  274.        
  275.         chomp $distro; chomp $fdistro;
  276.         last;
  277.     }
  278.  
  279.     return ""
  280.         if $distro eq "";
  281.  
  282.     $/ = $slurp; $distro = lc $distro;
  283.     eval "\$distro = \$$distro;";
  284.     push @info, "$colors[0]Distro\t\t\t$colors[1]$fdistro$nocolor";
  285.     $distro;
  286. }
RAW Paste Data
Challenge yourself this year...
Learn something new in 2017
Top