#!/usr/bin/env perl
# vim:ts=4:sw=4:expandtab
#
-# © 2012 Michael Stapelberg
+# © 2012-2013 Michael Stapelberg
#
# No dependencies except for perl ≥ v5.10
'dmenu=s' => \$dmenu_cmd,
'entry-type=s' => \@entry_types,
'version' => sub {
- say "dmenu-desktop 1.3 © 2012 Michael Stapelberg";
+ say "dmenu-desktop 1.5 © 2012-2013 Michael Stapelberg";
exit 0;
},
'help' => sub {
$names{$key} = $value;
} elsif ($key eq 'Exec' ||
$key eq 'TryExec' ||
+ $key eq 'Path' ||
$key eq 'Type') {
$apps{$base}->{$key} = $value;
} elsif ($key eq 'NoDisplay' ||
# open2 will just make dmenu’s STDERR go to our own STDERR.
my ($dmenu_out, $dmenu_in);
-my $pid = open2($dmenu_out, $dmenu_in, $dmenu_cmd);
+my $pid = eval {
+ open2($dmenu_out, $dmenu_in, $dmenu_cmd);
+} or do {
+ print STDERR "$@";
+ say STDERR "Running dmenu failed. Is dmenu installed at all? Try running dmenu -v";
+ exit 1;
+};
+
binmode $dmenu_in, ':utf8';
binmode $dmenu_out, ':utf8';
last;
}
if (!defined($app)) {
- die "Invalid input: “$choice” does not match any application.";
+ warn "Invalid input: “$choice” does not match any application. Trying to execute nevertheless.";
+ $app->{Name} = '';
+ $app->{Exec} = $choice;
+ # We assume that the app is old and does not support startup
+ # notifications because it doesn’t ship a desktop file.
+ $app->{StartupNotify} = 0;
+ $app->{_Location} = '';
}
}
# 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;
# Literal % characters are represented as %%.
$exec =~ s/%%/%/g;
+if (exists($app->{Path}) && $app->{Path} ne '') {
+ $exec = 'cd ' . $app->{Path} . ' && ' . $exec;
+}
+
my $nosn = '';
my $cmd;
if (exists($app->{Terminal}) && $app->{Terminal}) {
=head1 VERSION
-Version 1.3
+Version 1.5
=head1 AUTHOR