X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=i3-dmenu-desktop;h=cc72f1016429780c2e13a2ef8378c119701cb9e0;hb=d217cddb42b835e974af40294994385eb2cf9a52;hp=cccc1dc56cbcaca59ee7c3976aaa7b4a78079f49;hpb=35aec2f03849a6238e4d216270b3ed9e9ef252a5;p=i3%2Fi3 diff --git a/i3-dmenu-desktop b/i3-dmenu-desktop index cccc1dc5..cc72f101 100755 --- a/i3-dmenu-desktop +++ b/i3-dmenu-desktop @@ -1,7 +1,7 @@ #!/usr/bin/env perl # vim:ts=4:sw=4:expandtab # -# © 2012-2013 Michael Stapelberg +# © 2012-2014 Michael Stapelberg # # No dependencies except for perl ≥ v5.10 @@ -55,8 +55,12 @@ 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; +my $valid_types = { + name => 1, + command => 1, + filename => 1, +}; +@entry_types = grep { exists($valid_types->{$_}) } @entry_types; @entry_types = ('name', 'command') unless @entry_types; # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ @@ -257,7 +261,7 @@ for my $app (keys %apps) { } } - if ('name' ~~ @entry_types) { + if ((scalar grep { $_ eq 'name' } @entry_types) > 0) { 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 @@ -273,22 +277,22 @@ for my $app (keys %apps) { $choices{$name} = $app; } - if ('command' ~~ @entry_types) { + if ((scalar grep { $_ eq 'command' } @entry_types) > 0) { my ($command) = split(' ', $apps{$app}->{Exec}); # Don’t add “geany” if “Geany” is already present. my @keys = map { lc } keys %choices; - next if lc(basename($command)) ~~ @keys; + next if (scalar grep { $_ eq lc(basename($command)) } @keys) > 0; $choices{basename($command)} = $app; } - if ('filename' ~~ @entry_types) { + if ((scalar grep { $_ eq 'filename' } @entry_types) > 0) { 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; + next if (scalar grep { $_ eq lc($filename) } @keys) > 0; $choices{$filename} = $app; } @@ -302,7 +306,7 @@ for my $app (keys %apps) { # }; # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ -# ┃ Run dmenu to ask the user for her choice ┃ +# ┃ Run dmenu to ask the user for their choice ┃ # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ # open2 will just make dmenu’s STDERR go to our own STDERR. @@ -376,6 +380,7 @@ sub quote { $choice = quote($choice); $location = quote($location); +$name = quote($name); # Remove deprecated field codes, as the spec dictates. $exec =~ s/%[dDnNvm]//g; @@ -405,7 +410,7 @@ $exec =~ s/%k/$location/g; $exec =~ s/%%/%/g; if (exists($app->{Path}) && $app->{Path} ne '') { - $exec = 'cd ' . $app->{Path} . ' && ' . $exec; + $exec = 'cd ' . quote($app->{Path}) . ' && ' . $exec; } my $nosn = '';