Skip to content

Instantly share code, notes, and snippets.

@emasaka
Created April 2, 2011 10:24
Show Gist options
  • Save emasaka/899378 to your computer and use it in GitHub Desktop.
Save emasaka/899378 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use LWP::UserAgent;
use File::Spec::Functions;
use Gtk2::Notify -init, 'Bijo Linux Notify';
sub notify_send {
my ($title, $icon) = @_;
Gtk2::Notify->new($title, '', $icon)->show;
}
sub mirror_image {
my ($file, $dir) = @_;
LWP::UserAgent->new->mirror("http://bijo-linux.com/girls_images/${file}",
catfile($dir, $file) )->code;
}
sub bijo_linux_notify {
my ($cmd, $imgdir) = @_;
my $basename = "${cmd}.jpg";
my $localfile = catfile($imgdir, $basename);
my $stopfile = catfile($imgdir, "${cmd}.notexist");
mkdir $imgdir;
unless (-e $localfile) {
return if -e $stopfile;
my $code = mirror_image $basename, $imgdir;
if ($code != 200) {
mkdir $stopfile if $code == 404;
return;
}
}
notify_send $cmd, $localfile;
}
sub parse_shell_command { # workaround
my ($cmdline) = @_;
my @elms = split(/\s+/, $cmdline);
my $cmd;
do { $cmd = shift @elms } while @elms && ($cmd =~ /=/);
$cmd;
}
my $cmd = parse_shell_command $ARGV[0];
if ($cmd =~ /^[\w-]+$/) {
bijo_linux_notify $cmd, catfile($ENV{HOME}, '.bijo-linux-image');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment