#!/usr/bin/perl

# Coded by Trizen
# Email: echo dHJpemVueEBnbWFpbC5jb20K | base64 -d
# Website: http://trizen.go.ro

$c = $ARGV[0];
$z = "\e[0m";
for ($nr = 0; $nr <= $#ARGV; ++$nr) {
    push @argvs, $ARGV[$nr];
}
if ($c =~ /-h|--help/) {
    die "
Usage: $0 [...]

Colors:
\t-d --default
\t-r --red
\t-g --green
\t-b --black
\t-p --purple
\t-c --cyan
\t-w --white
\t
Options:
\t-s  :  take screenshot (using scrot)

";
}
open FILE, "$ENV{'HOME'}/.gtkrc-2.0";
while (defined($_ = <FILE>)) {
    if ($_ =~ /gtk-theme-name=['"]([^"']+)/) {
        $gtk_theme = $1;
    }
    if ($_ =~ /gtk-font-name=['"]([^"']+)/) {
        $font = $1;
    }
    if ($_ =~ /gtk-icon-theme-name=['"]([^"']+)/) {
        $icon_theme = $1;
    }
}
close FILE;
unless ($gtk_theme) {
    $gtk_theme = 'Unknown';
}
unless ($font) {
    $font = 'Unknown';
}
unless ($icon_theme) {
    $icon_theme = 'Unknown';
}
if ($c eq '' or $c eq '-n' and $ARGV[1] eq '' or $c eq '-s') {
    $c1 = "\e[0;34m";
    $c2 = $c1;
    $c2 =~ s/\[0/[1/;
}
else {
    @colors = "
\e[0;34m' -d --default
\e[0;31m' -r --red
\e[0;32m' -g --green
\e[0;33m' -y --yellow
\e[0;30m' -b --black
\e[0;35m' -p --purple
\e[0;36m' -c --cyan
\e[0;37m' -w --white
";
}
(%wm) = (
'awesome', 'Awesome', 'beryl', 'Beryl', 'blackbox', 'Blackbox',
'compiz', 'Compiz', 'dwm', 'DWM', 'enlightenment', 'Enlightenment',
'fluxbox', 'Fluxbox', 'fvwm', 'FVWM', 'i3', 'i3', 'weewm', 'WeeWM',
'sawfish', 'Sawfish', 'qlwm', 'qLWM', 'echinus', 'Echinus', 'w9wm', 'w9wm',
'hackedbox', 'Hackedbox', 'scrotwm', 'Scrotwm', 'twm', 'twm', 'vtwm', 'VtWM',
'9wm', '9wm', 'swm', 'swm', 'flwm', 'FlWM', 'jwm', 'JWM', 'icewm', 'IceWM',
'kwin', 'KWin', 'metacity', 'Metacity', 'musca', 'Musca', 'openbox', 'Openbox',
'pekwm', 'PekWM', 'ratpoison', 'ratpoison', 'scrotwm', 'ScrotWM',
'wmaker', 'WMaker','wmfs', 'Wmfs', 'wmii', 'wmii', 'xmonad', 'xmonad'
);
$psx = `ps -A`;
foreach $wm (keys %wm) {
    if ($psx =~ /([\W]+)$wm/) {
        $WM = $wm;
    }
}
foreach $Wm (values %wm) {
    if ($WM =~ /$Wm/i) {
        $WM = $Wm;
    }
}
if ($WM eq '') {
    $WM = 'Unknown';
}
foreach $color (@colors) {
    foreach $arg (@argvs) {
        if ($color =~ /(.+)'(.*)$arg/) {
            $c1 = $1;
            $c2 = $c1;
            $c2 =~ s/\[0/[1/;
        }
    }
}
$ram = `free`;
if ($ram =~ /cache:([\ ]+)([\d]+)/) {
    $usedram = $2;
    $usedram = $usedram / 1024;
    $usedram =~ s/([\d]+)([\.]*)(.*)$/$1/;
}
else {
    $usedram = '';
}
if ($ram =~ /Mem:([\ ]+)([\d]+)/) {
    $totalram = $2;
    $totalram = $totalram / 1024;
    $totalram =~ s/([\d]+)([\.]*)(.*)$/$1/;
}
if ($usedram eq '') {
    if ($ram =~ /Mem:([\ ]+)([\d]+)([\ \t]*)([\d]+)/) {
        $usedram = $4;
        $usedram = $usedram / 1024;
        $usedram =~ s/([\d]+)([\.]*)(.*)$/$1/;
    }
}
$arch = `uname -m`;
if (-e '/etc/arch-release') {
    $distro = "Arch Linux $arch";
}
elsif (`ls /etc/` =~ /slackware-version/) {
    $distro = `cat /etc/$&`;
}
else {
    chomp($distro = `uname -o`);
    $distro .= " $arch";
}
if ($distro eq " $arch" and $arch =~ /(.+)/) {
    $distro = '';
    $distro = "Linux $arch";
}
if ($arch eq '' and $distro eq '') {
    $distro = "Unknown OS\n";
}
open CPU, '/proc/cpuinfo';
@cpu = <CPU>;
close CPU;
foreach $cpu (@cpu) {
    if ($cpu =~ /model name([\ \t]*): (.+)/) {
        $CPU = $2;
    }
    if ($cpu =~ /cpu MHz([\ \t]*): ([\d\.]+)/) {
        $freq = $2;
    }
}
if ($CPU eq '') {
    chomp($CPU = `uname -p`);
}
if (`uptime` =~ /up([\ \t]*)(.+)\, /) {
    $uptime = $2;
    if (not $uptime =~ /day/) {
        $uptime =~ s/,(.+)//;
    }
    else {
        $uptime =~ s/^([^\,]+),([\ \t]+)([^\,]+)(.+)/$1 & $3/;
    }
}
if ($distro =~ /Arch Linux/ or -e '/etc/frugalware-release') {
    $pkgs = `pacman -Q | wc -l`;
}
elsif (`ls /var/log/` =~ /\npackages\n/) {
    $pkgs = `ls /var/log/packages | wc -l`;
}
else {
    $pkgs = "Unknown\n";
}
if ($c1 eq '') {
    $c1 = "\e[0;34m";
    $c2 = $c1;
    $c2 =~ s/\[0/[1/;
}
@df = `df -TPh`;
foreach $df (@df) {
    if ($df =~ m[([\w]+)([\ \t]*)([\w\.]+)([\ \t]*)([\w\.]+)([\ \t]*)([\w\.]+)([\ \t]*)([\d]+)\% /(.*)] and not $1 =~ /tmpfs/) {
        $type = $1;
        $totalsize = $3;
        $used = $5;
        $free = $7;
        $usedprocent = " ($9%)";
        $mountpoint = "/$10";
    }
    $mountpoint =~ s[(.*)/(.+)$][$2];
    $mountpoint =~ s/(.+)/\u\L$1\E/g;
    if ($mountpoint eq '/') {
        $mountpoint = 'Root';
    }
    if ($mountpoint =~ /(.+)/) {
        if ($usedprocent eq ' (100%)') {
            $usedprocent = '';
        }
        push @partitions, " $c2 ${mountpoint}:$z $used / $totalsize$usedprocent ($type)";
    }
}
foreach $partition (@partitions) {
    next if $partition eq $lastpartition;
    push @p, $partition;
    $lastpartition = $partition;
}
$de = 'Desktop Environment';
if ($CPU =~ /([^\@]+)/) {
    $CPU = $1;
    $CPU =~ s/([\ \t]+)$//;
}
unless ($newlogo =~ /(.+)/) {
    print "\n            $c2-lvlvlvlvlvlv-$z            ";
    print "$c2 OS:$z $distro";
    print "         ${c2}_1vl1vlvlvlvlvlvlv=.$z         ";
    print "$c2 Hostname:$z ";
    system 'uname -n';
    print "      ${c2}_1vl1vlvlvlvlvlvlvlvlvlv=.$z      ";
    print "$c2 Kernel:$z ";
    system 'uname -r';
    print "    ${c2}__111llvl+' __...._   +1lv1vl=$z    ";
    print "$c2 Uptime:$z $uptime\n";
    print "   ${c2}_11vllvlv+  =vlvlvl1=  /1vlvv1=_$z   ";
    if ($psx =~ /xfce4-session/) {
        print "$c2 ${de}:$z XFCE4\n";
    }
    elsif ($psx =~ /lxsession/) {
        print "$c2 ${de}:$z LXDE\n";
    }
    elsif ($psx =~ /gnome-session/) {
        print "$c2 ${de}:$z GNOME\n";
    }
    elsif ($psx =~ /ksmserver/) {
        print "$c2 ${de}:$z KDE\n";
    }
    else {
        print "$c2 Window Manager:$z $WM\n";
    }
    print "  ${c2}_vvllvlvlv=  -+vlvlvlvlvlvlvlvdv=_$z  ";
    print "$c2 GTK+ theme:$z $gtk_theme\n";
    print " ${c2}_:lvlvlvlvlv=.     --^-^1lvlvlrlv1sl$z ";
    if ($icon_theme ne 'Unknown') {
		print "$c2 Icon theme:$z $icon_theme\n";
    }
    else {
        print "$c2 Font name:$z $font\n";
    }
    print " $c2=llvlvvlvlvv11lvl=....   -lvlevlvlvv$z ";
    print "$c2 Packages:$z $pkgs";
    print " $c2=lvlvlvlvll-^+1vv11111v_  vlkllvllvl$z ";
    print "$c2 RAM:$z $usedram MB / $totalram MB\n";
    print " $c2=lvlvlvlvl1   +1vv1v1lv  _llvlvlvlvl$z ";
    print "$c2 CPU:$z $CPU\n";
    print "  $c2+1lv |vlvl     -^-^-   _1olvlvlvlv$z ";
    print "$p[0]\n";
    print "   ${c2}1vl |lvlvlvlvlvlvlvlvv1vlvlvlvlv$z  ";
    print "$p[1]\n";
    print "    $c2+1 ^^^^^^^^^^^^^^^^^^^^^^^^vl-$z   ";
    print "$p[2]\n";
    print "      $c2-+uvlvlvlvlvlvlvlvlvlvlv+_$z     ";
    print "$p[3]\n";
    print "         $c2-lvlvlvlvlvlvlvlvlv-$z        ";
    print "$p[4]\n";
    print "            $c2-vlvlvlvlvlvl-$z           ";
    print "$p[5]\n";
    print "\n";
}
foreach $argv (@argvs) {
    if ($argv =~ /s/) {
        exec 'scrot -cd 5';
    }
}

