.i3/i3-dmenu-desktop

Mon, 02 Jun 2014 17:04:14 -0400

author
Meredith Howard <mhoward@roomag.org>
date
Mon, 02 Jun 2014 17:04:14 -0400
changeset 21
aa620cdf1022
child 22
96aa7ad42dfe
permissions
-rwxr-xr-x

i3: add customized i3-dmenu-desktop that caches menu data

21
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
1 #!/usr/bin/env perl
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
2 # vim:ts=4:sw=4:expandtab
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
3 #
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
4 # © 2012-2013 Michael Stapelberg
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
5 #
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
6 # No dependencies except for perl ≥ v5.10
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
7
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
8 use strict;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
9 use warnings qw(FATAL utf8);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
10 use Data::Dumper;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
11 use IPC::Open2;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
12 use POSIX qw(locale_h);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
13 use File::Find;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
14 use File::Basename qw(basename);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
15 use File::Temp qw(tempfile);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
16 use Getopt::Long;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
17 use Pod::Usage;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
18 use v5.10;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
19 use utf8;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
20 use open ':encoding(UTF-8)';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
21
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
22 use Storable qw( nstore retrieve );
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
23
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
24 binmode STDOUT, ':utf8';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
25 binmode STDERR, ':utf8';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
26
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
27 # reads in a whole file
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
28 sub slurp {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
29 my ($filename) = @_;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
30 open(my $fh, '<', $filename) or die "$!";
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
31 local $/;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
32 my $result;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
33 eval {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
34 $result = <$fh>;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
35 };
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
36 if ($@) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
37 warn "Could not read $filename: $@";
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
38 return undef;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
39 } else {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
40 return $result;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
41 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
42 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
43
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
44 my @entry_types;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
45 my $dmenu_cmd = 'dmenu -b -i -p ] -nf \#CCC -nb \#555';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
46 my $result = GetOptions(
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
47 'dmenu=s' => \$dmenu_cmd,
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
48 'entry-type=s' => \@entry_types,
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
49 'version' => sub {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
50 say "dmenu-desktop 1.5 © 2012-2013 Michael Stapelberg";
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
51 exit 0;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
52 },
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
53 'help' => sub {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
54 pod2usage(-exitval => 0);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
55 });
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
56
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
57 die "Could not parse command line options" unless $result;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
58
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
59 my ( %apps, %choices );
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
60 my $cachefile = $ENV{HOME} . '/.cache/i3-dmenu-desktop.bin';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
61
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
62 if ( -r $cachefile ){
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
63 my @cache = @{ retrieve( $cachefile ) };
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
64 %apps = %{ shift @cache };
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
65 %choices = %{ shift @cache };
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
66 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
67 else {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
68
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
69 # Filter entry types and set default type(s) if none selected
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
70 my @valid_types = ('name', 'command', 'filename');
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
71 @entry_types = grep { $_ ~~ @valid_types } @entry_types;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
72 @entry_types = ('name', 'command') unless @entry_types;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
73
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
74 # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
75 # ┃ Convert LC_MESSAGES into an ordered list of suffixes to search for in the ┃
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
76 # ┃ .desktop files (e.g. “Name[de_DE@euro]” for LC_MESSAGES=de_DE.UTF-8@euro ┃
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
77 # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
78
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
79 # For details on how the transformation of LC_MESSAGES to a list of keys that
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
80 # should be looked up works, refer to “Localized values for keys” of the
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
81 # “Desktop Entry Specification”:
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
82 # http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s04.html
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
83 my $lc_messages = setlocale(LC_MESSAGES);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
84
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
85 # Ignore the encoding (e.g. .UTF-8)
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
86 $lc_messages =~ s/\.[^@]+//g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
87
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
88 my @suffixes = ($lc_messages);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
89
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
90 # _COUNTRY and @MODIFIER are present
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
91 if ($lc_messages =~ /_[^@]+@/) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
92 my $no_modifier = $lc_messages;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
93 $no_modifier =~ s/@.*//g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
94 push @suffixes, $no_modifier;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
95
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
96 my $no_country = $lc_messages;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
97 $no_country =~ s/_[^@]+//g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
98 push @suffixes, $no_country;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
99 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
100
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
101 # Strip _COUNTRY and @MODIFIER if present
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
102 $lc_messages =~ s/[_@].*//g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
103 push @suffixes, $lc_messages;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
104
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
105 # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
106 # ┃ Read all .desktop files and store the values in which we are interested. ┃
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
107 # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
108
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
109 my %desktops;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
110 # See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
111 my $xdg_data_home = $ENV{XDG_DATA_HOME};
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
112 $xdg_data_home = $ENV{HOME} . '/.local/share' if
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
113 !defined($xdg_data_home) ||
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
114 $xdg_data_home eq '' ||
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
115 ! -d $xdg_data_home;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
116
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
117 my $xdg_data_dirs = $ENV{XDG_DATA_DIRS};
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
118 $xdg_data_dirs = '/usr/local/share/:/usr/share/' if
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
119 !defined($xdg_data_dirs) ||
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
120 $xdg_data_dirs eq '';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
121
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
122 my @searchdirs = ("$xdg_data_home/applications/");
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
123 for my $dir (split(':', $xdg_data_dirs)) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
124 push @searchdirs, "$dir/applications/";
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
125 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
126
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
127 # Cleanup the paths, maybe some application does not cope with double slashes
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
128 # (the field code %k is replaced with the .desktop file location).
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
129 @searchdirs = map { s,//,/,g; $_ } @searchdirs;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
130
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
131 # To avoid errors by File::Find’s find(), only pass existing directories.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
132 @searchdirs = grep { -d $_ } @searchdirs;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
133
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
134 find(
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
135 {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
136 wanted => sub {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
137 return unless substr($_, -1 * length('.desktop')) eq '.desktop';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
138 my $relative = $File::Find::name;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
139
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
140 # + 1 for the trailing /, which is missing in ::topdir.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
141 substr($relative, 0, length($File::Find::topdir) + 1) = '';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
142
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
143 # Don’t overwrite files with the same relative path, we search in
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
144 # descending order of importance.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
145 return if exists($desktops{$relative});
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
146
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
147 $desktops{$relative} = $File::Find::name;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
148 },
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
149 no_chdir => 1,
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
150 },
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
151 @searchdirs
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
152 );
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
153
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
154 for my $file (values %desktops) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
155 my $base = basename($file);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
156
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
157 # _ is an invalid character for a key, so we can use it for our own keys.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
158 $apps{$base}->{_Location} = $file;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
159
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
160 # Extract all “Name” and “Exec” keys from the [Desktop Entry] group
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
161 # and store them in $apps{$base}.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
162 my %names;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
163 my $content = slurp($file);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
164 next unless defined($content);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
165 my @lines = split("\n", $content);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
166 for my $line (@lines) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
167 my $first = substr($line, 0, 1);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
168 next if $line eq '' || $first eq '#';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
169 next unless ($line eq '[Desktop Entry]' ..
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
170 ($first eq '[' &&
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
171 substr($line, -1) eq ']' &&
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
172 $line ne '[Desktop Entry]'));
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
173 next if $first eq '[';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
174
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
175 my ($key, $value) = ($line =~ /^
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
176 (
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
177 [A-Za-z0-9-]+ # the spec specifies these as valid key characters
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
178 (?:\[[^]]+\])? # possibly, there as a locale suffix
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
179 )
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
180 \s* = \s* # whitespace around = should be ignored
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
181 (.*) # no restrictions on the values
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
182 $/x);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
183
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
184 if ($key =~ /^Name/) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
185 $names{$key} = $value;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
186 } elsif ($key eq 'Exec' ||
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
187 $key eq 'TryExec' ||
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
188 $key eq 'Path' ||
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
189 $key eq 'Type') {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
190 $apps{$base}->{$key} = $value;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
191 } elsif ($key eq 'NoDisplay' ||
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
192 $key eq 'Hidden' ||
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
193 $key eq 'StartupNotify' ||
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
194 $key eq 'Terminal') {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
195 # Values of type boolean must either be string true or false,
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
196 # see “Possible value types”:
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
197 # http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s03.html
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
198 $apps{$base}->{$key} = ($value eq 'true');
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
199 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
200 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
201
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
202 for my $suffix (@suffixes) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
203 next unless exists($names{"Name[$suffix]"});
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
204 $apps{$base}->{Name} = $names{"Name[$suffix]"};
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
205 last;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
206 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
207
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
208 # Fallback to unlocalized “Name”.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
209 $apps{$base}->{Name} = $names{Name} unless exists($apps{$base}->{Name});
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
210 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
211
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
212 # %apps now looks like this:
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
213 #
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
214 # %apps = {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
215 # 'evince.desktop' => {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
216 # 'Exec' => 'evince %U',
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
217 # 'Name' => 'Dokumentenbetrachter',
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
218 # '_Location' => '/usr/share/applications/evince.desktop'
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
219 # },
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
220 # 'gedit.desktop' => {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
221 # 'Exec' => 'gedit %U',
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
222 # 'Name' => 'gedit',
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
223 # '_Location' => '/usr/share/applications/gedit.desktop'
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
224 # }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
225 # };
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
226
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
227 # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
228 # ┃ Turn %apps inside out to provide Name → filename lookup. ┃
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
229 # ┃ The Name is what we display in dmenu later. ┃
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
230 # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
231
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
232 for my $app (keys %apps) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
233 my $name = $apps{$app}->{Name};
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
234
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
235 # Don’t try to use .desktop files which don’t have Type=application
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
236 next if (!exists($apps{$app}->{Type}) ||
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
237 $apps{$app}->{Type} ne 'Application');
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
238
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
239 # Skip broken files (Type=application, but no Exec key).
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
240 if (!exists($apps{$app}->{Exec}) ||
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
241 $apps{$app}->{Exec} eq '') {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
242 warn 'File ' . $apps{$app}->{_Location} . ' is broken: it contains Type=Application, but no Exec key/value pair.';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
243 next;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
244 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
245
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
246 # Don’t offer apps which have NoDisplay == true or Hidden == true.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
247 # See http://wiki.xfce.org/howto/customize-menu#hide_menu_entries
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
248 # for the difference between NoDisplay and Hidden.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
249 next if (exists($apps{$app}->{NoDisplay}) && $apps{$app}->{NoDisplay}) ||
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
250 (exists($apps{$app}->{Hidden}) && $apps{$app}->{Hidden});
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
251
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
252 if (exists($apps{$app}->{TryExec})) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
253 my $tryexec = $apps{$app}->{TryExec};
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
254 if (substr($tryexec, 0, 1) eq '/') {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
255 # Skip if absolute path is not executable.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
256 next unless -x $tryexec;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
257 } else {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
258 # Search in $PATH for the executable.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
259 my $found = 0;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
260 for my $path (split(':', $ENV{PATH})) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
261 next unless -x "$path/$tryexec";
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
262 $found = 1;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
263 last;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
264 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
265 next unless $found;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
266 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
267 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
268
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
269 if ('name' ~~ @entry_types) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
270 if (exists($choices{$name})) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
271 # There are two .desktop files which contain the same “Name” value.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
272 # I’m not sure if that is allowed to happen, but we disambiguate the
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
273 # situation by appending “ (2)”, “ (3)”, etc. to the name.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
274 #
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
275 # An example of this happening is exo-file-manager.desktop and
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
276 # thunar-settings.desktop, both of which contain “Name=File Manager”.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
277 my $inc = 2;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
278 $inc++ while exists($choices{"$name ($inc)"});
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
279 $name = "$name ($inc)";
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
280 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
281
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
282 $choices{$name} = $app;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
283 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
284
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
285 if ('command' ~~ @entry_types) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
286 my ($command) = split(' ', $apps{$app}->{Exec});
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
287
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
288 # Don’t add “geany” if “Geany” is already present.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
289 my @keys = map { lc } keys %choices;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
290 next if lc(basename($command)) ~~ @keys;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
291
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
292 $choices{basename($command)} = $app;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
293 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
294
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
295 if ('filename' ~~ @entry_types) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
296 my $filename = basename($app, '.desktop');
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
297
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
298 # Don’t add “geany” if “Geany” is already present.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
299 my @keys = map { lc } keys %choices;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
300 next if lc($filename) ~~ @keys;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
301
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
302 $choices{$filename} = $app;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
303 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
304 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
305
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
306 nstore [ \%apps, \%choices ], $cachefile;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
307 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
308
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
309
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
310 # %choices now looks like this:
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
311 #
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
312 # %choices = {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
313 # 'Dokumentenbetrachter' => 'evince.desktop',
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
314 # 'gedit' => 'gedit.desktop'
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
315 # };
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
316
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
317 # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
318 # ┃ Run dmenu to ask the user for her choice ┃
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
319 # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
320
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
321 # open2 will just make dmenu’s STDERR go to our own STDERR.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
322 my ($dmenu_out, $dmenu_in);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
323 my $pid = eval {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
324 open2($dmenu_out, $dmenu_in, $dmenu_cmd);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
325 } or do {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
326 print STDERR "$@";
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
327 say STDERR "Running dmenu failed. Is dmenu installed at all? Try running dmenu -v";
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
328 exit 1;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
329 };
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
330
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
331 binmode $dmenu_in, ':utf8';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
332 binmode $dmenu_out, ':utf8';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
333
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
334 # Feed dmenu the possible choices.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
335 say $dmenu_in $_ for sort keys %choices;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
336 close($dmenu_in);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
337
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
338 waitpid($pid, 0);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
339 my $status = ($? >> 8);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
340
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
341 # Pass on dmenu’s exit status if there was an error.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
342 exit $status unless $status == 0;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
343
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
344 my $choice = <$dmenu_out>;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
345 # dmenu ≥ 4.4 adds a newline after the choice
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
346 chomp($choice);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
347 my $app;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
348 # Exact match: the user chose “Avidemux (GTK+)”
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
349 if (exists($choices{$choice})) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
350 $app = $apps{$choices{$choice}};
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
351 $choice = '';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
352 } else {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
353 # Not an exact match: the user entered “Avidemux (GTK+) ~/movie.mp4”
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
354 for my $possibility (keys %choices) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
355 next unless substr($choice, 0, length($possibility)) eq $possibility;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
356 $app = $apps{$choices{$possibility}};
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
357 substr($choice, 0, length($possibility)) = '';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
358 # Remove whitespace separating the entry and arguments.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
359 $choice =~ s/^\s//g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
360 last;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
361 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
362 if (!defined($app)) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
363 warn "Invalid input: “$choice” does not match any application. Trying to execute nevertheless.";
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
364 $app->{Name} = '';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
365 $app->{Exec} = $choice;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
366 # We assume that the app is old and does not support startup
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
367 # notifications because it doesn’t ship a desktop file.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
368 $app->{StartupNotify} = 0;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
369 $app->{_Location} = '';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
370 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
371 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
372
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
373 # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
374 # ┃ Make i3 start the chosen application. ┃
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
375 # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
376
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
377 my $name = $app->{Name};
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
378 my $exec = $app->{Exec};
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
379 my $location = $app->{_Location};
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
380
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
381 # Quote as described by “The Exec key”:
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
382 # http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s06.html
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
383 sub quote {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
384 my ($str) = @_;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
385 $str =~ s/("|`|\$|\\)/\\$1/g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
386 $str = qq|"$str"| if $str ne "";
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
387 return $str;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
388 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
389
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
390 $choice = quote($choice);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
391 $location = quote($location);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
392
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
393 # Remove deprecated field codes, as the spec dictates.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
394 $exec =~ s/%[dDnNvm]//g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
395
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
396 # Replace filename field codes with the rest of the command line.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
397 # Note that we assume the user uses precisely one file name,
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
398 # not multiple file names.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
399 $exec =~ s/%[fF]/$choice/g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
400
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
401 # If the program works with URLs,
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
402 # we assume the user provided a URL instead of a filename.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
403 # As per the spec, there must be at most one of %f, %u, %F or %U present.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
404 $exec =~ s/%[uU]/$choice/g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
405
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
406 # The translated name of the application.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
407 $exec =~ s/%c/$name/g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
408
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
409 # XXX: Icons are not implemented. Is the complexity (looking up the path if
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
410 # only a name is given) actually worth it?
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
411 #$exec =~ s/%i/--icon $icon/g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
412 $exec =~ s/%i//g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
413
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
414 # location of .desktop file
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
415 $exec =~ s/%k/$location/g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
416
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
417 # Literal % characters are represented as %%.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
418 $exec =~ s/%%/%/g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
419
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
420 if (exists($app->{Path}) && $app->{Path} ne '') {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
421 $exec = 'cd ' . $app->{Path} . ' && ' . $exec;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
422 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
423
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
424 my $nosn = '';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
425 my $cmd;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
426 if (exists($app->{Terminal}) && $app->{Terminal}) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
427 # For applications which specify “Terminal=true” (e.g. htop.desktop),
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
428 # we need to create a temporary script that contains the full command line
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
429 # as the syntax for starting commands with arguments varies from terminal
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
430 # emulator to terminal emulator.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
431 # Then, we launch that script with i3-sensible-terminal.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
432 my ($fh, $filename) = tempfile();
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
433 binmode($fh, ':utf8');
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
434 say $fh <<EOT;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
435 #!/bin/sh
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
436 rm $filename
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
437 exec $exec
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
438 EOT
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
439 close($fh);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
440 chmod 0755, $filename;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
441
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
442 $cmd = qq|exec i3-sensible-terminal -e "$filename"|;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
443 } else {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
444 # i3 executes applications by passing the argument to i3’s “exec” command
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
445 # as-is to $SHELL -c. The i3 parser supports quoted strings: When a string
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
446 # starts with a double quote ("), everything is parsed as-is until the next
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
447 # double quote which is NOT preceded by a backslash (\).
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
448 #
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
449 # Therefore, we escape all double quotes (") by replacing them with \"
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
450 $exec =~ s/"/\\"/g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
451
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
452 if (exists($app->{StartupNotify}) && !$app->{StartupNotify}) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
453 $nosn = '--no-startup-id';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
454 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
455 $cmd = qq|exec $nosn "$exec"|;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
456 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
457
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
458 system('i3-msg', $cmd) == 0 or die "Could not launch i3-msg: $?";
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
459
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
460 =encoding utf-8
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
461
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
462 =head1 NAME
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
463
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
464 i3-dmenu-desktop - run .desktop files with dmenu
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
465
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
466 =head1 SYNOPSIS
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
467
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
468 i3-dmenu-desktop [--dmenu='dmenu -i'] [--entry-type=name]
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
469
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
470 =head1 DESCRIPTION
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
471
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
472 i3-dmenu-desktop is a script which extracts the (localized) name from
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
473 application .desktop files, offers the user a choice via dmenu(1) and then
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
474 starts the chosen application via i3 (for startup notification support).
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
475 The advantage of using .desktop files instead of dmenu_run(1) is that dmenu_run
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
476 offers B<all> binaries in your $PATH, including non-interactive utilities like
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
477 "sed". Also, .desktop files contain a proper name, information about whether
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
478 the application runs in a terminal and whether it supports startup
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
479 notifications.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
480
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
481 The .desktop files are searched in $XDG_DATA_HOME/applications (by default
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
482 $HOME/.local/share/applications) and in the "applications" subdirectory of each
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
483 entry of $XDG_DATA_DIRS (by default /usr/local/share/:/usr/share/).
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
484
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
485 Files with the same name in $XDG_DATA_HOME/applications take precedence over
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
486 files in $XDG_DATA_DIRS, so that you can overwrite parts of the system-wide
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
487 .desktop files by copying them to your local directory and making changes.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
488
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
489 i3-dmenu-desktop displays the "Name" value in the localized version depending
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
490 on LC_MESSAGES as specified in the Desktop Entry Specification.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
491
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
492 You can pass a filename or URL (%f/%F and %u/%U field codes in the .desktop
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
493 file respectively) by appending it to the name of the application. E.g., if you
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
494 want to launch "GNU Emacs 24" with the patch /tmp/foobar.txt, you would type
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
495 "emacs", press TAB, type " /tmp/foobar.txt" and press ENTER.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
496
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
497 .desktop files with Terminal=true are started using i3-sensible-terminal(1).
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
498
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
499 .desktop files with NoDisplay=true or Hidden=true are skipped.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
500
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
501 UTF-8 is supported, of course, but dmenu does not support displaying all
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
502 glyphs. E.g., xfce4-terminal.desktop's Name[fi]=Pääte will be displayed just
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
503 fine, but not its Name[ru]=Терминал.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
504
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
505 =head1 OPTIONS
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
506
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
507 =over
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
508
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
509 =item B<--dmenu=command>
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
510
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
511 Execute command instead of 'dmenu -i'. This option can be used to pass custom
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
512 parameters to dmenu, or to make i3-dmenu-desktop start a custom (patched?)
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
513 version of dmenu.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
514
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
515 =item B<--entry-type=type>
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
516
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
517 Display the (localized) "Name" (type = name), the command (type = command) or
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
518 the (*.desktop) filename (type = filename) in dmenu. This option can be
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
519 specified multiple times.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
520
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
521 Examples are "GNU Image Manipulation Program" (type = name), "gimp" (type =
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
522 command), and "libreoffice-writer" (type = filename).
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
523
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
524 =back
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
525
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
526 =head1 VERSION
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
527
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
528 Version 1.5
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
529
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
530 =head1 AUTHOR
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
531
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
532 Michael Stapelberg, C<< <michael at i3wm.org> >>
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
533
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
534 =head1 LICENSE AND COPYRIGHT
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
535
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
536 Copyright 2012 Michael Stapelberg.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
537
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
538 This program is free software; you can redistribute it and/or modify it
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
539 under the terms of the BSD license.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
540
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
541 =cut

mercurial