.i3/i3-dmenu-desktop

Fri, 16 Sep 2016 12:12:59 -0400

author
Meredith Howard <mhoward@roomag.org>
date
Fri, 16 Sep 2016 12:12:59 -0400
changeset 388
50ed49b3d1dc
parent 267
d125935c7197
permissions
-rwxr-xr-x

Update for osx 10.11

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

mercurial