i3-dmenu-desktop: add --entry-type=[name|command|both]

The new default is 'both' to add "GNU Image Manipulation Program" as
well as "gimp-2.8" to the menu.
This commit is contained in:
Michael Stapelberg 2012-12-10 00:28:32 +01:00
parent 66f7a607f6
commit f044eb9e90
1 changed files with 31 additions and 14 deletions

View File

@ -29,11 +29,13 @@ sub slurp {
<$fh>; <$fh>;
} }
my $entry_type = 'both';
my $dmenu_cmd = 'dmenu -i'; my $dmenu_cmd = 'dmenu -i';
my $result = GetOptions( my $result = GetOptions(
'dmenu=s' => \$dmenu_cmd, 'dmenu=s' => \$dmenu_cmd,
'entry-type=s' => \$entry_type,
'version' => sub { 'version' => sub {
say "dmenu-desktop 1.0 © 2012 Michael Stapelberg"; say "dmenu-desktop 1.1 © 2012 Michael Stapelberg";
exit 0; exit 0;
}, },
'help' => sub { 'help' => sub {
@ -225,6 +227,7 @@ for my $app (keys %apps) {
} }
} }
if ($entry_type eq 'name' || $entry_type eq 'both') {
if (exists($choices{$name})) { if (exists($choices{$name})) {
# There are two .desktop files which contain the same “Name” value. # There are two .desktop files which contain the same “Name” value.
# Im not sure if that is allowed to happen, but we disambiguate the # Im not sure if that is allowed to happen, but we disambiguate the
@ -238,6 +241,12 @@ for my $app (keys %apps) {
} }
$choices{$name} = $app; $choices{$name} = $app;
}
if ($entry_type eq 'command' || $entry_type eq 'both') {
my ($command) = split(' ', $apps{$app}->{Exec});
$choices{basename($command)} = $app;
}
} }
# %choices now looks like this: # %choices now looks like this:
@ -378,7 +387,7 @@ system('i3-msg', $cmd) == 0 or die "Could not launch i3-msg: $?";
=head1 SYNOPSIS =head1 SYNOPSIS
i3-dmenu-desktop [--dmenu='dmenu -i'] i3-dmenu-desktop [--dmenu='dmenu -i'] [--entry-type=both]
=head1 DESCRIPTION =head1 DESCRIPTION
@ -425,11 +434,19 @@ Execute command instead of 'dmenu -i'. This option can be used to pass custom
parameters to dmenu, or to make i3-dmenu-desktop start a custom (patched?) parameters to dmenu, or to make i3-dmenu-desktop start a custom (patched?)
version of dmenu. 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.
Examples are "GNU Image Manipulation Program" (type = name), "gimp" (type =
command) and both (type = both).
=back =back
=head1 VERSION =head1 VERSION
Version 1.0 Version 1.1
=head1 AUTHOR =head1 AUTHOR