5 # |
5 # |
6 # No dependencies except for perl ≥ v5.10 |
6 # No dependencies except for perl ≥ v5.10 |
7 |
7 |
8 use strict; |
8 use strict; |
9 use warnings qw(FATAL utf8); |
9 use warnings qw(FATAL utf8); |
|
10 use v5.10; |
|
11 |
|
12 my $dmenu_cmd; |
|
13 my @entry_types; |
|
14 |
|
15 BEGIN { |
|
16 $dmenu_cmd = 'dmenu -b -i -p ] -nf \#CCC -nb \#555'; |
|
17 |
|
18 use Getopt::Long; |
|
19 my $result = GetOptions( |
|
20 'dmenu=s' => \$dmenu_cmd, |
|
21 'entry-type=s' => \@entry_types, |
|
22 'version' => sub { |
|
23 say "dmenu-desktop 1.5~custom~mhoward"; |
|
24 exit 0; |
|
25 }, |
|
26 'help' => sub { |
|
27 pod2usage(-exitval => 0); |
|
28 }); |
|
29 |
|
30 die "Could not parse command line options" unless $result; |
|
31 |
|
32 # if j4-dmenu-desktop is available, let it take over asap |
|
33 # https://github.com/enkore/j4-dmenu-desktop |
|
34 if ( -x $ENV{HOME} . '/.i3/j4-dmenu-desktop' ){ |
|
35 exec $ENV{HOME} . "/.i3/j4-dmenu-desktop --dmenu='${dmenu_cmd}'"; |
|
36 } |
|
37 |
|
38 #otherwise we do the same thing as stock i3-dmenu-desktop, but cache the result |
|
39 } |
|
40 |
10 use Data::Dumper; |
41 use Data::Dumper; |
11 use IPC::Open2; |
42 use IPC::Open2; |
12 use POSIX qw(locale_h); |
43 use POSIX qw(locale_h); |
13 use File::Find; |
44 use File::Find; |
14 use File::Basename qw(basename); |
45 use File::Basename qw(basename); |
15 use File::Temp qw(tempfile); |
46 use File::Temp qw(tempfile); |
16 use Getopt::Long; |
|
17 use Pod::Usage; |
47 use Pod::Usage; |
18 use v5.10; |
|
19 use utf8; |
48 use utf8; |
20 use open ':encoding(UTF-8)'; |
49 use open ':encoding(UTF-8)'; |
21 |
50 |
22 use Storable qw( nstore retrieve ); |
51 use Storable qw( nstore retrieve ); |
23 |
52 |
38 return undef; |
67 return undef; |
39 } else { |
68 } else { |
40 return $result; |
69 return $result; |
41 } |
70 } |
42 } |
71 } |
43 |
|
44 my @entry_types; |
|
45 my $dmenu_cmd = 'dmenu -b -i -p ] -nf \#CCC -nb \#555'; |
|
46 my $result = GetOptions( |
|
47 'dmenu=s' => \$dmenu_cmd, |
|
48 'entry-type=s' => \@entry_types, |
|
49 'version' => sub { |
|
50 say "dmenu-desktop 1.5 © 2012-2013 Michael Stapelberg"; |
|
51 exit 0; |
|
52 }, |
|
53 'help' => sub { |
|
54 pod2usage(-exitval => 0); |
|
55 }); |
|
56 |
|
57 die "Could not parse command line options" unless $result; |
|
58 |
72 |
59 my ( %apps, %choices ); |
73 my ( %apps, %choices ); |
60 my $cachefile = $ENV{HOME} . '/.cache/i3-dmenu-desktop.bin'; |
74 my $cachefile = $ENV{HOME} . '/.cache/i3-dmenu-desktop.bin'; |
61 |
75 |
62 if ( -r $cachefile ){ |
76 if ( -r $cachefile ){ |