Allow bin/hosts to have subdirectories

This commit is contained in:
Peter J. Holzer 2022-10-16 09:10:02 +02:00
parent bcab6770c3
commit 357d10f4af
2 changed files with 19 additions and 4 deletions

View File

@ -16,11 +16,26 @@ mkdir "$ENV{HOME}/log/";
mkdir "$ENV{HOME}/log/xfce-xterm-launcher/";
open my $log, ">>", "$ENV{HOME}/log/xfce-xterm-launcher/" . strftime("%Y-%m", localtime);
my @dirs = ("$ENV{HOME}/bin/hosts",
grep -d, glob("$ENV{HOME}/bin/hosts/*"));
my $i = 0;
for (@desktop_files) {
my $content = read_file($_);
my ($exec) = $content =~ m/^Exec=xterm -e (.*)/m;
next unless defined $exec;
my $age = -A "$ENV{HOME}/bin/hosts/$exec";
my $age = age($exec);
say $log join("\t", $^T, ++$i, $exec, $age);
}
sub age {
my ($exec) = @_;
if ($exec =~ m{^/}) {
return -A $exec;
}
for my $d (@dirs) {
my $age = -A "$d/$exec";
return $age if defined $age;
}
return;
}

View File

@ -6,8 +6,6 @@ use strict;
use File::Slurp;
use Data::Dumper;
use experimental qw(autoderef);
my $launcher = $ARGV[0];
my $verbose = 0;
@ -22,7 +20,9 @@ for (@desktop_files) {
$desktop_files{$name} = { name => $name, filename => $_, content => $content }
}
my @xterm_scripts = glob("$ENV{HOME}/bin/hosts/*");
my @xterm_scripts = grep !-d,
(glob("$ENV{HOME}/bin/hosts/*"),
glob("$ENV{HOME}/bin/hosts/*/*"));
@xterm_scripts = sort { -A $a <=> -A $b } @xterm_scripts;
@xterm_scripts = @xterm_scripts[0..31] if @xterm_scripts > 32;
for my $xterm_script (@xterm_scripts) {