]> git.sur5r.net Git - i3/i3/blobdiff - i3-dmenu-desktop
Add a new IPC event for changes on windows.
[i3/i3] / i3-dmenu-desktop
index 3a52faa57537b5c1005d2c8e30e3e59819ce9fed..794120356e8dd8a15db063dd786302c7719c75bb 100755 (executable)
@@ -39,11 +39,11 @@ 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";
         exit 0;
@@ -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:
@@ -418,7 +433,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,11 +482,12 @@ 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