]> git.sur5r.net Git - i3/i3/blobdiff - i3-dmenu-desktop
Merge branch 'next'
[i3/i3] / i3-dmenu-desktop
index 3a52faa57537b5c1005d2c8e30e3e59819ce9fed..085c4f1c3e5780aeb6d31f6182a02840aa41402e 100755 (executable)
@@ -39,13 +39,13 @@ sub slurp {
     }
 }
 
-my $entry_type = 'both';
+my @entry_types;
 my $dmenu_cmd = 'dmenu -i';
 my $result = GetOptions(
     'dmenu=s' => \$dmenu_cmd,
-    'entry-type=s' => \$entry_type,
+    'entry-type=s' => \@entry_types,
     'version' => sub {
-        say "dmenu-desktop 1.3 © 2012 Michael Stapelberg";
+        say "dmenu-desktop 1.4 © 2012 Michael Stapelberg";
         exit 0;
     },
     'help' => sub {
@@ -54,6 +54,11 @@ my $result = GetOptions(
 
 die "Could not parse command line options" unless $result;
 
+# Filter entry types and set default type(s) if none selected
+my @valid_types = ('name', 'command', 'filename');
+@entry_types = grep { $_ ~~ @valid_types } @entry_types;
+@entry_types = ('name', 'command') unless @entry_types;
+
 # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
 # ┃ Convert LC_MESSAGES into an ordered list of suffixes to search for in the ┃
 # ┃ .desktop files (e.g. “Name[de_DE@euro]” for LC_MESSAGES=de_DE.UTF-8@euro  ┃
@@ -251,7 +256,7 @@ for my $app (keys %apps) {
         }
     }
 
-    if ($entry_type eq 'name' || $entry_type eq 'both') {
+    if ('name' ~~ @entry_types) {
         if (exists($choices{$name})) {
             # There are two .desktop files which contain the same “Name” value.
             # I’m not sure if that is allowed to happen, but we disambiguate the
@@ -267,7 +272,7 @@ for my $app (keys %apps) {
         $choices{$name} = $app;
     }
 
-    if ($entry_type eq 'command' || $entry_type eq 'both') {
+    if ('command' ~~ @entry_types) {
         my ($command) = split(' ', $apps{$app}->{Exec});
 
         # Don’t add “geany” if “Geany” is already present.
@@ -276,6 +281,16 @@ for my $app (keys %apps) {
 
         $choices{basename($command)} = $app;
     }
+
+    if ('filename' ~~ @entry_types) {
+        my $filename = basename($app, '.desktop');
+
+        # Don’t add “geany” if “Geany” is already present.
+        my @keys = map { lc } keys %choices;
+        next if lc($filename) ~~ @keys;
+
+        $choices{$filename} = $app;
+    }
 }
 
 # %choices now looks like this:
@@ -367,6 +382,7 @@ $exec =~ s/%c/$name/g;
 # XXX: Icons are not implemented. Is the complexity (looking up the path if
 # only a name is given) actually worth it?
 #$exec =~ s/%i/--icon $icon/g;
+$exec =~ s/%i//g;
 
 # location of .desktop file
 $exec =~ s/%k/$location/g;
@@ -418,7 +434,7 @@ system('i3-msg', $cmd) == 0 or die "Could not launch i3-msg: $?";
 
 =head1 SYNOPSIS
 
-    i3-dmenu-desktop [--dmenu='dmenu -i'] [--entry-type=both]
+    i3-dmenu-desktop [--dmenu='dmenu -i'] [--entry-type=name]
 
 =head1 DESCRIPTION
 
@@ -467,17 +483,18 @@ version of dmenu.
 
 =item B<--entry-type=type>
 
-Display the (localized) "Name" (type = name) or the command (type = command) or
-both (type = both) in dmenu.
+Display the (localized) "Name" (type = name), the command (type = command) or
+the (*.desktop) filename (type = filename) in dmenu. This option can be
+specified multiple times.
 
 Examples are "GNU Image Manipulation Program" (type = name), "gimp" (type =
-command) and both (type = both).
+command), and "libreoffice-writer" (type = filename).
 
 =back
 
 =head1 VERSION
 
-Version 1.3
+Version 1.4
 
 =head1 AUTHOR