X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=i3-dmenu-desktop;h=aee5dc2f4e32eeb4b82099dc0633e1a911a6e0e4;hb=919ac9c7ef4be41bd3c2ef923cd38ba523d1f8c3;hp=3b81cb20ce008097b9f3dbd412f1fd08a6ea2c87;hpb=1994eea5da1c83f35e5793ef6ca72a91d09eb824;p=i3%2Fi3 diff --git a/i3-dmenu-desktop b/i3-dmenu-desktop index 3b81cb20..aee5dc2f 100755 --- a/i3-dmenu-desktop +++ b/i3-dmenu-desktop @@ -279,16 +279,42 @@ for my $app (keys %apps) { } $choices{$name} = $app; + next; } if ((scalar grep { $_ eq 'command' } @entry_types) > 0) { - my ($command) = split(' ', $apps{$app}->{Exec}); + my $command = $apps{$app}->{Exec}; + + # Handle escape sequences (should be done for all string values, but does + # matter here). + my %escapes = ( + '\\s' => ' ', + '\\n' => '\n', + '\\t' => '\t', + '\\r' => '\r', + '\\\\' => '\\', + ); + $command =~ s/(\\[sntr\\])/$escapes{$1}/go; + + # Extract executable + if ($command =~ m/^\s*([^\s\"]+)(?:\s|$)/) { + # No quotes + $command = $1; + } elsif ($command =~ m/^\s*\"([^\"\\]*(?:\\.[^\"\\]*)*)\"(?:\s|$)/) { + # Quoted, remove quotes and fix escaped characters + $command = $1; + $command =~ s/\\([\"\`\$\\])/$1/g; + } else { + # Invalid quotes, fallback to whitespace + ($command) = split(' ', $command); + } # Don’t add “geany” if “Geany” is already present. my @keys = map { lc } keys %choices; - next if (scalar grep { $_ eq lc(basename($command)) } @keys) > 0; - - $choices{basename($command)} = $app; + if (!(scalar grep { $_ eq lc(basename($command)) } @keys) > 0) { + $choices{basename($command)} = $app; + } + next; } if ((scalar grep { $_ eq 'filename' } @entry_types) > 0) {