]> nmode's Git Repositories - Fey/blobdiff - lib/App/Fey.pm
Add option to open all files/URIs in a single instance
[Fey] / lib / App / Fey.pm
index 025fb091cc9471a760cfcc7d540376f7ee4fc233..9939a5c729fe1fb5e5cce3e02cf82e1ed8de4936 100644 (file)
@@ -8,16 +8,16 @@ our @EXPORT_OK = qw(fey);
 our $version = '0.01';
 
 sub new {
 our $version = '0.01';
 
 sub new {
-    my ($class, $args) = @_;
+    my ($class, $options) = @_;
     my $config = do ($ENV{XDG_CONFIG_HOME} // "$ENV{HOME}/.config") . '/fey/config.pl';
 
     my $self = {
     my $config = do ($ENV{XDG_CONFIG_HOME} // "$ENV{HOME}/.config") . '/fey/config.pl';
 
     my $self = {
-        mime_query => $args->{mime_query} // $config->{mime_query} // sub {
+        mime_query => $options->{mime_query} // $config->{mime_query} // sub {
             open my $mime_type, '-|', 'file', '--brief', '--mime-type', $_[0];
             <$mime_type>;
         },
             open my $mime_type, '-|', 'file', '--brief', '--mime-type', $_[0];
             <$mime_type>;
         },
-        contexts => $args->{contexts} // $config->{contexts} // { default => sub { 1 } },
-        targets => $args->{targets} // $config->{targets} // {}
+        contexts => $options->{contexts} // $config->{contexts} // { default => sub { 1 } },
+        targets => $options->{targets} // $config->{targets} // {}
     };
 
     bless $self, $class;
     };
 
     bless $self, $class;
@@ -25,6 +25,9 @@ sub new {
 
 sub launch {
     my $self = shift;
 
 sub launch {
     my $self = shift;
+    my $options = ref $_[0] ? shift : {};
+
+    die "No files or URIs specified.\n" unless @_;
 
     ARG: for my $file_or_uri (@_) {
         if ($file_or_uri =~ m|^file://(.+)|) {
 
     ARG: for my $file_or_uri (@_) {
         if ($file_or_uri =~ m|^file://(.+)|) {
@@ -44,6 +47,10 @@ sub launch {
                     my $associations = $target->{associations};
                     for my $context (keys %{ $associations }) {
                         if ($self->{contexts}->{$context}->()) {
                     my $associations = $target->{associations};
                     for my $context (keys %{ $associations }) {
                         if ($self->{contexts}->{$context}->()) {
+                            if ($options->{single}) {
+                                $associations->{$context}->(@_);
+                                return;
+                            }
                             $associations->{$context}->($file_or_uri);
                             next ARG;
                         }
                             $associations->{$context}->($file_or_uri);
                             next ARG;
                         }
@@ -55,5 +62,5 @@ sub launch {
 }
 
 sub fey {
 }
 
 sub fey {
-    App::Fey->new(ref $_[0] ? shift : {})->launch(@_ ? @_ : die 'Error: No files or URIs specified.');
+    App::Fey->new(ref $_[0] ? $_[0] : {})->launch(@_);
 }
 }