Skip to content

Commit 5424331

Browse files
committed
Ported several improvements from obmenu-generator.
- Support for the "Path" key. - Create icons and cache.db in ~/.cache
1 parent e28c0a9 commit 5424331

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

fbmenugen

+35-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/perl
22

3-
# Copyright (C) 2010-2022 Daniel "Trizen" Șuteu <echo dHJpemVuQHByb3Rvbm1haWwuY29tCg== | base64 -d>.
3+
# Copyright (C) 2010-2023 Daniel "Trizen" Șuteu <echo dHJpemVuQHByb3Rvbm1haWwuY29tCg== | base64 -d>.
44
#
55
# This program is free software: you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License as published by
@@ -22,15 +22,15 @@
2222
# Name: fbmenugen
2323
# License: GPLv3
2424
# Created on: 01 August 2010
25-
# Latest edit on: 06 September 2022
25+
# Latest edit on: 22 September 2023
2626
# https://github.com/trizen/fbmenugen
2727

2828
use 5.014;
2929
use File::Spec;
3030
use Linux::DesktopFiles 0.25;
3131

3232
my $pkgname = 'fbmenugen';
33-
my $version = '0.87';
33+
my $version = '0.88';
3434

3535
my ($with_icons, $db_clean, $create_menu, $pipe, $reload_config, $update_config);
3636

@@ -43,14 +43,16 @@ my $home_dir =
4343
|| `echo -n ~`;
4444

4545
my $xdg_config_home = $ENV{XDG_CONFIG_HOME} || "$home_dir/.config";
46+
my $xdg_cache_home = $ENV{XDG_CACHE_HOME} || "$home_dir/.cache";
4647

4748
my $config_dir = "$xdg_config_home/$pkgname";
4849
my $schema_file = "$config_dir/schema.pl";
4950
my $config_file = "$config_dir/config.pl";
50-
my $cache_db = "$config_dir/cache.db";
51+
my $cache_dir = "$xdg_cache_home/$pkgname";
5152
my $fluxbox_dir = "$home_dir/.fluxbox";
5253
my $menu_file = "$fluxbox_dir/menu";
53-
my $icons_dir = "$config_dir/icons";
54+
my $cache_db = "$cache_dir/cache.db";
55+
my $icons_dir = "$cache_dir/icons";
5456

5557
sub usage {
5658
print <<"HELP";
@@ -179,6 +181,12 @@ if (not -d $config_dir) {
179181
or die "$0: can't create configuration directory `$config_dir': $!\n";
180182
}
181183

184+
if (not -d $cache_dir) {
185+
require File::Path;
186+
File::Path::make_path($cache_dir)
187+
or die "$0: can't create cache directory `$cache_dir': $!\n";
188+
}
189+
182190
if ($with_icons and not -d $icons_dir) {
183191
remove_database($cache_db);
184192
require File::Path;
@@ -281,12 +289,23 @@ if ($CONFIG{VERSION} != $version) {
281289
dump_configuration();
282290
}
283291

292+
#<<<
293+
my @desktop_files_paths = do {
294+
my %seen;
295+
grep { !$seen{$_}++ } (
296+
($ENV{XDG_DATA_DIRS} ? split(/:/, $ENV{XDG_DATA_DIRS}) : ()),
297+
@{$CONFIG{'Linux::DesktopFiles'}{desktop_files_paths}},
298+
);
299+
};
300+
#>>>
301+
284302
my $desk_obj = Linux::DesktopFiles->new(
285303
%{$CONFIG{'Linux::DesktopFiles'}},
304+
desktop_files_paths => \@desktop_files_paths,
286305

287306
categories => [map { exists($_->{cat}) ? $_->{cat}[0] : () } @$SCHEMA],
288307

289-
keys_to_keep => ['Name', 'Exec',
308+
keys_to_keep => ['Name', 'Exec', 'Path',
290309
($with_icons ? 'Icon' : ()),
291310
(
292311
ref($CONFIG{'Linux::DesktopFiles'}{skip_entry}) eq 'ARRAY'
@@ -475,6 +494,7 @@ foreach my $file ($desk_obj->get_desktop_files) {
475494
%info = (
476495
Name => $entry->{Name} // next,
477496
Exec => $entry->{Exec} // next,
497+
Path => $entry->{Path} // '',
478498

479499
(
480500
$with_icons
@@ -487,6 +507,15 @@ foreach my $file ($desk_obj->get_desktop_files) {
487507
);
488508
#>>>
489509

510+
# Support for the Path key
511+
if ($info{Path} ne '') {
512+
require Encode;
513+
my $path = Encode::decode_utf8($info{Path});
514+
my $exec = Encode::decode_utf8($info{Exec});
515+
$exec = "$^X -e 'chdir(\$ARGV[0]) && exec(\$ARGV[1])' \Q$path\E \Q$exec\E";
516+
$info{Exec} = Encode::encode_utf8($exec);
517+
}
518+
490519
eval {
491520

492521
state $x = do {

0 commit comments

Comments
 (0)