.i3/i3-dmenu-desktop

Mon, 02 Jun 2014 17:31:29 -0400

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

i3: prefer j4-dmenu-desktop if available

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);
22
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
10 use v5.10;
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
11
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
12 my $dmenu_cmd;
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
13 my @entry_types;
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
14
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
15 BEGIN {
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
16 $dmenu_cmd = 'dmenu -b -i -p ] -nf \#CCC -nb \#555';
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
17
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
18 use Getopt::Long;
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
19 my $result = GetOptions(
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
20 'dmenu=s' => \$dmenu_cmd,
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
21 'entry-type=s' => \@entry_types,
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
22 'version' => sub {
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
23 say "dmenu-desktop 1.5~custom~mhoward";
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
24 exit 0;
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
25 },
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
26 'help' => sub {
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
27 pod2usage(-exitval => 0);
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
28 });
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
29
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
30 die "Could not parse command line options" unless $result;
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
31
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
32 # if j4-dmenu-desktop is available, let it take over asap
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
33 # https://github.com/enkore/j4-dmenu-desktop
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
34 if ( -x $ENV{HOME} . '/.i3/j4-dmenu-desktop' ){
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
35 exec $ENV{HOME} . "/.i3/j4-dmenu-desktop --dmenu='${dmenu_cmd}'";
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
36 }
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
37
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
38 #otherwise we do the same thing as stock i3-dmenu-desktop, but cache the result
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
39 }
96aa7ad42dfe i3: prefer j4-dmenu-desktop if available
Meredith Howard <mhoward@roomag.org>
parents: 21
diff changeset
40
21
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
41 use Data::Dumper;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
42 use IPC::Open2;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
43 use POSIX qw(locale_h);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
44 use File::Find;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
45 use File::Basename qw(basename);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
46 use File::Temp qw(tempfile);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
47 use Pod::Usage;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
48 use utf8;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
49 use open ':encoding(UTF-8)';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
50
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
51 use Storable qw( nstore retrieve );
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 binmode STDOUT, ':utf8';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
54 binmode STDERR, ':utf8';
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 # reads in a whole file
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
57 sub slurp {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
58 my ($filename) = @_;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
59 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
60 local $/;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
61 my $result;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
62 eval {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
63 $result = <$fh>;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
64 };
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
65 if ($@) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
66 warn "Could not read $filename: $@";
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
67 return undef;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
68 } else {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
69 return $result;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
70 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
71 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
72
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
73 my ( %apps, %choices );
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
74 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
75
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
76 if ( -r $cachefile ){
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
77 my @cache = @{ retrieve( $cachefile ) };
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
78 %apps = %{ shift @cache };
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
79 %choices = %{ shift @cache };
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
80 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
81 else {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
82
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
83 # 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
84 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
85 @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
86 @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
87
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
88 # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
89 # ┃ 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
90 # ┃ .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
91 # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
92
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
93 # 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
94 # 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
95 # “Desktop Entry Specification”:
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
96 # 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
97 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
98
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
99 # 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
100 $lc_messages =~ s/\.[^@]+//g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
101
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
102 my @suffixes = ($lc_messages);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
103
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
104 # _COUNTRY and @MODIFIER are present
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
105 if ($lc_messages =~ /_[^@]+@/) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
106 my $no_modifier = $lc_messages;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
107 $no_modifier =~ s/@.*//g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
108 push @suffixes, $no_modifier;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
109
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
110 my $no_country = $lc_messages;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
111 $no_country =~ s/_[^@]+//g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
112 push @suffixes, $no_country;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
113 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
114
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
115 # 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
116 $lc_messages =~ s/[_@].*//g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
117 push @suffixes, $lc_messages;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
118
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
119 # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
120 # ┃ 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
121 # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
122
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
123 my %desktops;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
124 # 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
125 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
126 $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
127 !defined($xdg_data_home) ||
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
128 $xdg_data_home eq '' ||
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
129 ! -d $xdg_data_home;
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 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
132 $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
133 !defined($xdg_data_dirs) ||
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
134 $xdg_data_dirs eq '';
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 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
137 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
138 push @searchdirs, "$dir/applications/";
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
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
141 # 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
142 # (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
143 @searchdirs = map { s,//,/,g; $_ } @searchdirs;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
144
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
145 # 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
146 @searchdirs = grep { -d $_ } @searchdirs;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
147
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
148 find(
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
149 {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
150 wanted => sub {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
151 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
152 my $relative = $File::Find::name;
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 # + 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
155 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
156
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
157 # 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
158 # descending order of importance.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
159 return if exists($desktops{$relative});
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
160
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
161 $desktops{$relative} = $File::Find::name;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
162 },
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
163 no_chdir => 1,
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
164 },
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
165 @searchdirs
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
166 );
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
167
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
168 for my $file (values %desktops) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
169 my $base = basename($file);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
170
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
171 # _ 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
172 $apps{$base}->{_Location} = $file;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
173
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
174 # 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
175 # 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
176 my %names;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
177 my $content = slurp($file);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
178 next unless defined($content);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
179 my @lines = split("\n", $content);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
180 for my $line (@lines) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
181 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
182 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
183 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
184 ($first eq '[' &&
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
185 substr($line, -1) eq ']' &&
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
186 $line ne '[Desktop Entry]'));
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
187 next if $first eq '[';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
188
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
189 my ($key, $value) = ($line =~ /^
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
190 (
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
191 [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
192 (?:\[[^]]+\])? # 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
193 )
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
194 \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
195 (.*) # no restrictions on the values
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
196 $/x);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
197
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
198 if ($key =~ /^Name/) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
199 $names{$key} = $value;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
200 } elsif ($key eq 'Exec' ||
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
201 $key eq 'TryExec' ||
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
202 $key eq 'Path' ||
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
203 $key eq 'Type') {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
204 $apps{$base}->{$key} = $value;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
205 } elsif ($key eq 'NoDisplay' ||
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
206 $key eq 'Hidden' ||
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
207 $key eq 'StartupNotify' ||
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
208 $key eq 'Terminal') {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
209 # 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
210 # see “Possible value types”:
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
211 # 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
212 $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
213 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
214 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
215
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
216 for my $suffix (@suffixes) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
217 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
218 $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
219 last;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
220 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
221
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
222 # Fallback to unlocalized “Name”.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
223 $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
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 # %apps now looks like this:
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 # %apps = {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
229 # 'evince.desktop' => {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
230 # 'Exec' => 'evince %U',
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
231 # 'Name' => 'Dokumentenbetrachter',
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
232 # '_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
233 # },
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
234 # 'gedit.desktop' => {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
235 # 'Exec' => 'gedit %U',
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
236 # 'Name' => 'gedit',
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
237 # '_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
238 # }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
239 # };
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
240
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
241 # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
242 # ┃ 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
243 # ┃ 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
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 for my $app (keys %apps) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
247 my $name = $apps{$app}->{Name};
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
248
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
249 # 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
250 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
251 $apps{$app}->{Type} ne 'Application');
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
252
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
253 # 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
254 if (!exists($apps{$app}->{Exec}) ||
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
255 $apps{$app}->{Exec} eq '') {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
256 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
257 next;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
258 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
259
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
260 # 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
261 # 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
262 # 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
263 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
264 (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
265
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
266 if (exists($apps{$app}->{TryExec})) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
267 my $tryexec = $apps{$app}->{TryExec};
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
268 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
269 # 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
270 next unless -x $tryexec;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
271 } else {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
272 # 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
273 my $found = 0;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
274 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
275 next unless -x "$path/$tryexec";
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
276 $found = 1;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
277 last;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
278 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
279 next unless $found;
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
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
283 if ('name' ~~ @entry_types) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
284 if (exists($choices{$name})) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
285 # 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
286 # 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
287 # 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
288 #
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
289 # 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
290 # 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
291 my $inc = 2;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
292 $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
293 $name = "$name ($inc)";
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
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
296 $choices{$name} = $app;
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
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
299 if ('command' ~~ @entry_types) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
300 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
301
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
302 # 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
303 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
304 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
305
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
306 $choices{basename($command)} = $app;
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 if ('filename' ~~ @entry_types) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
310 my $filename = basename($app, '.desktop');
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 # 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
313 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
314 next if lc($filename) ~~ @keys;
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 $choices{$filename} = $app;
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 }
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 nstore [ \%apps, \%choices ], $cachefile;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
321 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
322
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
323
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
324 # %choices now looks like this:
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
325 #
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
326 # %choices = {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
327 # 'Dokumentenbetrachter' => 'evince.desktop',
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
328 # 'gedit' => 'gedit.desktop'
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 # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
332 # ┃ 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
333 # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
334
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
335 # 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
336 my ($dmenu_out, $dmenu_in);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
337 my $pid = eval {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
338 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
339 } or do {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
340 print STDERR "$@";
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
341 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
342 exit 1;
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
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
345 binmode $dmenu_in, ':utf8';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
346 binmode $dmenu_out, ':utf8';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
347
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
348 # Feed dmenu the possible choices.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
349 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
350 close($dmenu_in);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
351
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
352 waitpid($pid, 0);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
353 my $status = ($? >> 8);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
354
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
355 # 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
356 exit $status unless $status == 0;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
357
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
358 my $choice = <$dmenu_out>;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
359 # 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
360 chomp($choice);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
361 my $app;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
362 # 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
363 if (exists($choices{$choice})) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
364 $app = $apps{$choices{$choice}};
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
365 $choice = '';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
366 } else {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
367 # 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
368 for my $possibility (keys %choices) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
369 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
370 $app = $apps{$choices{$possibility}};
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
371 substr($choice, 0, length($possibility)) = '';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
372 # 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
373 $choice =~ s/^\s//g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
374 last;
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 if (!defined($app)) {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
377 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
378 $app->{Name} = '';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
379 $app->{Exec} = $choice;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
380 # 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
381 # 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
382 $app->{StartupNotify} = 0;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
383 $app->{_Location} = '';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
384 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
385 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
386
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
387 # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
388 # ┃ 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
389 # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
390
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
391 my $name = $app->{Name};
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
392 my $exec = $app->{Exec};
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
393 my $location = $app->{_Location};
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
394
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
395 # 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
396 # 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
397 sub quote {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
398 my ($str) = @_;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
399 $str =~ s/("|`|\$|\\)/\\$1/g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
400 $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
401 return $str;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
402 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
403
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
404 $choice = quote($choice);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
405 $location = quote($location);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
406
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
407 # 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
408 $exec =~ s/%[dDnNvm]//g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
409
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
410 # 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
411 # 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
412 # not multiple file names.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
413 $exec =~ s/%[fF]/$choice/g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
414
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
415 # 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
416 # 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
417 # 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
418 $exec =~ s/%[uU]/$choice/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 # 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
421 $exec =~ s/%c/$name/g;
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 # 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
424 # 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
425 #$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
426 $exec =~ s/%i//g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
427
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
428 # location of .desktop file
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
429 $exec =~ s/%k/$location/g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
430
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
431 # Literal % characters are represented as %%.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
432 $exec =~ s/%%/%/g;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
433
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
434 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
435 $exec = 'cd ' . $app->{Path} . ' && ' . $exec;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
436 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
437
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
438 my $nosn = '';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
439 my $cmd;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
440 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
441 # 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
442 # 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
443 # 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
444 # emulator to terminal emulator.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
445 # 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
446 my ($fh, $filename) = tempfile();
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
447 binmode($fh, ':utf8');
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
448 say $fh <<EOT;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
449 #!/bin/sh
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
450 rm $filename
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
451 exec $exec
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
452 EOT
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
453 close($fh);
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
454 chmod 0755, $filename;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
455
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
456 $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
457 } else {
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
458 # 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
459 # 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
460 # 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
461 # 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
462 #
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
463 # 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
464 $exec =~ s/"/\\"/g;
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 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
467 $nosn = '--no-startup-id';
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
468 }
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
469 $cmd = qq|exec $nosn "$exec"|;
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
470 }
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 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
473
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
474 =encoding utf-8
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
475
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
476 =head1 NAME
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
477
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
478 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
479
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
480 =head1 SYNOPSIS
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
481
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
482 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
483
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
484 =head1 DESCRIPTION
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
485
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
486 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
487 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
488 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
489 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
490 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
491 "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
492 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
493 notifications.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
494
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
495 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
496 $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
497 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
498
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
499 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
500 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
501 .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
502
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
503 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
504 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
505
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
506 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
507 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
508 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
509 "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
510
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
511 .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
512
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
513 .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
514
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
515 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
516 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
517 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
518
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
519 =head1 OPTIONS
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 =over
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
522
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
523 =item B<--dmenu=command>
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
524
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
525 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
526 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
527 version of dmenu.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
528
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
529 =item B<--entry-type=type>
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
530
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
531 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
532 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
533 specified multiple times.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
534
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
535 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
536 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
537
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
538 =back
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
539
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
540 =head1 VERSION
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
541
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
542 Version 1.5
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
543
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
544 =head1 AUTHOR
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
545
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
546 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
547
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
548 =head1 LICENSE AND COPYRIGHT
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
549
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
550 Copyright 2012 Michael Stapelberg.
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
551
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
552 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
553 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
554
aa620cdf1022 i3: add customized i3-dmenu-desktop that caches menu data
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
555 =cut

mercurial