i3-dmenu-desktop: List filenames of .desktop files
Patch status: merged
Patch by Mats
Long description:
In addition to 'name' and 'command', add a third entry type 'filename' to list the filenames of the .desktop files (e.g., 'firefox.desktop' would be display as 'firefox'). Command line option '--entry-type' can be specified multiple times. fixes #930
To apply this patch, use:
curl http://cr.i3wm.org/patch/29/raw.patch | git am
b/i3-dmenu-desktop
20 |
@@ -39,11 +39,11 @@ sub slurp { |
21 |
} |
22 |
} |
23 |
|
24 |
-my $entry_type = 'both'; |
25 |
+my @entry_types; |
26 |
my $dmenu_cmd = 'dmenu -i'; |
27 |
my $result = GetOptions( |
28 |
'dmenu=s' => \$dmenu_cmd, |
29 |
- 'entry-type=s' => \$entry_type, |
30 |
+ 'entry-type=s' => \@entry_types, |
31 |
'version' => sub { |
32 |
say "dmenu-desktop 1.3 © 2012 Michael Stapelberg"; |
33 |
exit 0; |
34 |
@@ -54,6 +54,11 @@ my $result = GetOptions( |
35 |
|
36 |
die "Could not parse command line options" unless $result; |
37 |
|
38 |
+# Filter entry types and set default type(s) if none selected |
39 |
+my @valid_types = ('name', 'command', 'filename'); |
40 |
+@entry_types = grep { $_ ~~ @valid_types } @entry_types; |
41 |
+@entry_types = ('name', 'command') unless @entry_types; |
42 |
+ |
43 |
# ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
44 |
# ┃ Convert LC_MESSAGES into an ordered list of suffixes to search for in the ┃ |
45 |
# ┃ .desktop files (e.g. “Name[de_DE@euro]” for LC_MESSAGES=de_DE.UTF-8@euro ┃ |
46 |
@@ -251,7 +256,7 @@ for my $app (keys %apps) { |
47 |
} |
48 |
} |
49 |
|
50 |
- if ($entry_type eq 'name' || $entry_type eq 'both') { |
51 |
+ if ('name' ~~ @entry_types) { |
52 |
if (exists($choices{$name})) { |
53 |
# There are two .desktop files which contain the same “Name” value. |
54 |
# I’m not sure if that is allowed to happen, but we disambiguate the |
55 |
@@ -267,7 +272,7 @@ for my $app (keys %apps) { |
56 |
$choices{$name} = $app; |
57 |
} |
58 |
|
59 |
- if ($entry_type eq 'command' || $entry_type eq 'both') { |
60 |
+ if ('command' ~~ @entry_types) { |
61 |
my ($command) = split(' ', $apps{$app}->{Exec}); |
62 |
|
63 |
# Don’t add “geany” if “Geany” is already present. |
64 |
@@ -276,6 +281,16 @@ for my $app (keys %apps) { |
65 |
|
66 |
$choices{basename($command)} = $app; |
67 |
} |
68 |
+ |
69 |
+ if ('filename' ~~ @entry_types) { |
70 |
+ my $filename = basename($app, '.desktop'); |
71 |
+ |
72 |
+ # Don’t add “geany” if “Geany” is already present. |
73 |
+ my @keys = map { lc } keys %choices; |
74 |
+ next if lc($filename) ~~ @keys; |
75 |
+ |
76 |
+ $choices{$filename} = $app; |
77 |
+ } |
78 |
} |
79 |
|
80 |
# %choices now looks like this: |
81 |
@@ -418,7 +433,7 @@ system('i3-msg', $cmd) == 0 or die "Could not launch i3-msg: $?"; |
82 |
|
83 |
=head1 SYNOPSIS |
84 |
|
85 |
- i3-dmenu-desktop [--dmenu='dmenu -i'] [--entry-type=both] |
86 |
+ i3-dmenu-desktop [--dmenu='dmenu -i'] [--entry-type=name] |
87 |
|
88 |
=head1 DESCRIPTION |
89 |
|
90 |
@@ -467,11 +482,12 @@ version of dmenu. |
91 |
|
92 |
=item B<--entry-type=type> |
93 |
|
94 |
-Display the (localized) "Name" (type = name) or the command (type = command) or |
95 |
-both (type = both) in dmenu. |
96 |
+Display the (localized) "Name" (type = name), the command (type = command) or |
97 |
+the (*.desktop) filename (type = filename) in dmenu. This option can be |
98 |
+specified multiple times. |
99 |
|
100 |
Examples are "GNU Image Manipulation Program" (type = name), "gimp" (type = |
101 |
-command) and both (type = both). |
102 |
+command), and "libreoffice-writer" (type = filename). |
103 |
|
104 |
=back |
105 |
|