Initial release.

This commit is contained in:
Peter J. Holzer 2014-08-27 11:49:04 +02:00
commit 90812cb89b
2 changed files with 109 additions and 0 deletions

6
GNUmakefile Normal file
View File

@ -0,0 +1,6 @@
all:
install: $(HOME)/bin/xfce-xterm-launcher-update
$(HOME)/bin/%: %
cp $^ $@

103
xfce-xterm-launcher-update Executable file
View File

@ -0,0 +1,103 @@
#!/usr/bin/perl
use warnings;
use strict;
use File::Slurp;
use Data::Dumper;
my $launcher = $ARGV[0];
my $launcher_dir = "$ENV{HOME}/.config/xfce4/panel/launcher-$launcher";
my @desktop_files = glob("$launcher_dir/*.desktop");
my %desktop_files;
for (@desktop_files) {
my $content = read_file($_);
my ($name) = $content =~ /^Name=(\N*)/ms;
$desktop_files{$name} = { name => $name, filename => $_, content => $content }
}
my @xterm_scripts = glob("$ENV{HOME}/bin/hosts/*");
@xterm_scripts = sort { -A $a <=> -A $b } @xterm_scripts;
@xterm_scripts = @xterm_scripts[0..31];
for my $xterm_script (@xterm_scripts) {
my ($name) = $xterm_script =~ m{([^/]+)$};
if ($desktop_files{$name}) {
$desktop_files{$name}{current} = 1;
parse($desktop_files{$name});
my $icon_file = icon_file($name);
if ($desktop_files{$name}{content_fields}{Icon} ne $icon_file) {
$desktop_files{$name}{content_fields}{Icon} = $icon_file;
replace($desktop_files{$name});
say STDERR "replaced desktop entry $desktop_files{$name}{filename} for $name";
}
} else {
$desktop_files{$name} = {
content_fields => {
Name=> $name,
Type=> 'Application',
Exec=> "xterm -e $name",
Terminal=> 'false',
Icon=> icon_file($name),
Path=> "$ENV{HOME}/tmp",
StartupNotify=> 'false',
},
current => 1
};
replace($desktop_files{$name});
say STDERR "created new desktop entry $desktop_files{$name}{filename} for $name";
}
}
$desktop_files{XTerm}{current} = 1; # we always want that
for my $name (sort keys %desktop_files) {
unless ($desktop_files{$name}{current}) {
say STDERR "deleting obsolete desktop entry $desktop_files{$name}{filename} for $name";
unlink($desktop_files{$name}{filename});
}
}
sub icon_file {
my ($name) = @_;
for ("$ENV{HOME}/icons/$name.png",
"$ENV{HOME}/icons/$name.jpg") {
return $_ if -f $_;
}
return "xterm-color_48x48";
}
sub parse {
my ($desktop_file) = @_;
for (split(/\n/, $desktop_file->{content})) {
if (my ($k, $v) = m/^(\w+)=(.+)/) {
$desktop_file->{content_fields}{$k} = $v;
}
}
}
sub replace {
my ($desktop_file) = @_;
if ($desktop_file->{filename}) {
unlink($desktop_file->{filename});
}
my $filename;
my $base = "$launcher_dir/" . time();
my $ext = 0;
# XXX - possible race condition, but we don't expect this script
# to run concurrently for the same user.
for(;;) {
$filename = "$base$ext.desktop";
last unless (-f $filename);
$ext++;
}
open(my $fh, '>', $filename);
print $fh "[Desktop Entry]\n";
for my $k (sort keys $desktop_file->{content_fields}) {
print $fh "$k=$desktop_file->{content_fields}{$k}\n";
}
close($fh);
}