Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit fcdae02956912f5be7e13e7428c97e8f803deb2a @hakobe committed Nov 20, 2010
Showing with 234 additions and 0 deletions.
  1. +44 −0 autoload/unite/sources/script.vim
  2. +16 −0 examples/bookmarks.pl
  3. +29 −0 examples/gmail.pl
  4. +123 −0 examples/itunes.pl
  5. +22 −0 examples/twitter_user.pl
@@ -0,0 +1,44 @@
+" script.vim
+
+let s:source = {
+\ 'name': 'script',
+\ }
+
+function! s:source.on_init(args, context)
+ let s:buffer = {
+ \ 'path' : expand('%'),
+ \ }
+endfunction
+
+function! s:get_word(line)
+
+ let word = (split(a:line, ","))[0]
+ return word
+endfunction
+
+function! s:get_command(line)
+ let command = (split(a:line, ","))[1]
+ return command
+endfunction
+
+function! s:source.gather_candidates(args, context)
+ if len(a:args) <2
+ call unite#print_error("please specify runner and script")
+ return []
+ endif
+
+ let runner = a:args[0]
+ let script = a:args[1]
+ let lines = split(system(printf("%s %s %s", runner, script, s:buffer.path)), "\n")
+ return map(lines, '{
+ \ "word": s:get_word(v:val),
+ \ "source": "script",
+ \ "kind": "command",
+ \ "action__command": s:get_command(v:val),
+ \ }')
+endfunction
+
+function! unite#sources#script#define()
+ return [s:source]
+endfunction
+
@@ -0,0 +1,16 @@
+use strict;
+use warnings;
+
+use XML::Feed;
+use URI;
+use Perl6::Say;
+use URI::Fetch;
+
+my $target = 'http://b.hatena.ne.jp/hotentry.rss';
+
+my $res = URI::Fetch->fetch( $target );
+my $feed = XML::Feed->parse(\($res->content));
+
+for my $entry ($feed->entries) {
+ say sprintf("%s,call system('open %s')", $entry->title, $entry->link);
+}
@@ -0,0 +1,29 @@
+use strict;
+use warnings;
+
+use XML::Feed;
+use Perl6::Say;
+use LWP::UserAgent;
+use HTTP::Request::Common;
+use Config::Pit;
+
+my $config = pit_get("mail.google.com", require => {
+ "username" => "your username",
+ "password" => "your password"
+});
+
+my $ua = LWP::UserAgent->new;
+
+my $req = GET('https://mail.google.com/mail/feed/atom');
+$req->authorization_basic($config->{username}, $config->{password});
+
+my $res = $ua->request($req);
+
+my $feed = XML::Feed->parse(\($res->content));
+
+for my $entry ($feed->entries) {
+ my $summary = $entry->summary->body;
+ $summary =~ s/^.*。\s+//g;
+ say sprintf(q<%s,call system('open "%s"')>, $summary, $entry->link);
+}
+
@@ -0,0 +1,123 @@
+use strict;
+use warnings;
+use Mac::AppleScript qw(RunAppleScript);
+use Perl6::Say;
+use FindBin;
+
+BEGIN {
+ $ENV{ITUNES_TELL} = 1;
+};
+
+my $me = "$0";
+my $mode = shift || '';
+
+if ($mode eq 'play_n') {
+ &play_n(@ARGV);
+}
+elsif ($mode eq 'play') {
+}
+elsif ($mode eq 'stop') {
+}
+elsif ($mode eq 'next') {
+}
+elsif ($mode eq 'prev') {
+}
+else {
+ &panel(@ARGV);
+ &list(@ARGV);
+}
+
+sub play {
+ my $script = <<"SCRIPT";
+ tell application "iTunes"
+ play
+ end tell
+SCRIPT
+ RunAppleScript($script);
+}
+
+sub stop {
+ my $script = <<"SCRIPT";
+ tell application "iTunes"
+ stop
+ end tell
+SCRIPT
+ RunAppleScript($script);
+}
+
+sub next {
+ my $script = <<"SCRIPT";
+ tell application "iTunes"
+ next track
+ end tell
+SCRIPT
+ RunAppleScript($script);
+}
+
+sub prev {
+ my $script = <<"SCRIPT";
+ tell application "iTunes"
+ previous track
+ end tell
+SCRIPT
+ RunAppleScript($script);
+}
+
+sub play_n {
+ my $n = shift;
+ my $script = <<"SCRIPT";
+ tell application "iTunes"
+ set cPlaylist to current playlist
+ play track $n of cPlaylist
+ end tell
+SCRIPT
+ RunAppleScript($script);
+}
+
+sub panel {
+ print <<"PANEL"
+|>,call system('perl $me play')
+[],call system('perl $me stop')
+>>,call system('perl $me next')
+<<,call system('perl $me prev')
+PANEL
+}
+
+sub list {
+ my $script = <<"SCRIPT";
+ tell application "iTunes"
+ set cPlaylist to current playlist
+ set resultString to ""
+ repeat with i from 1 to count of tracks in cPlaylist
+ set sName to name of track i in cPlaylist
+ set sArtist to artist of track i in cPlaylist
+ set sTime to time of track i in cPlaylist
+ set resultString to resultString & sName & "\t" & sArtist & "\t" & sTime & "\n"
+ end repeat
+ return resultString
+ end tell
+SCRIPT
+
+ my $result = RunAppleScript($script);
+ $result =~ s/^"//g;
+ $result =~ s/"$//g;
+
+ my $i = 1;
+ my $songs = [ map {
+ my $vals = [split /\t/, $_];
+ +{
+ position => $i++,
+ title => $vals->[0],
+ artist => $vals->[1],
+ time => $vals->[2],
+ };
+ } split /\n/, $result ];
+
+ for my $song (@$songs) {
+ say sprintf(qq<%s(%s) - %s,call system('perl %s play_n %s')>,
+ $song->{title}, $song->{time}, $song->{artist},
+ $me, $song->{position}
+ );
+ }
+}
+
@@ -0,0 +1,22 @@
+use strict;
+use warnings;
+
+use XML::Feed;
+use URI;
+use Perl6::Say;
+use Cache::File;
+use URI::Fetch;
+
+my $target = 'http://twitter.com/statuses/user_timeline/731253.rss';
+
+my $cache = Cache::File->new( cache_root => '/tmp/cache' );
+my $res = URI::Fetch->fetch(
+ $target,
+ Cache => $cache
+) or die URI::Fetch->errstr;
+
+my $feed = XML::Feed->parse(\($res->content));
+
+for my $entry ($feed->entries) {
+ say sprintf("%s,call system('open %s')", $entry->title, $entry->link);
+}

0 comments on commit fcdae02

Please sign in to comment.