initial commit
This commit is contained in:
commit
0df16a81cd
24
default.nix
Normal file
24
default.nix
Normal file
@ -0,0 +1,24 @@
|
||||
{ stdenv, perlPackages }:
|
||||
|
||||
stdenv.mkDerivation rec {
|
||||
pname = "urxvt-config-reload";
|
||||
version = "1.0";
|
||||
|
||||
src = ./src;
|
||||
|
||||
passthru.perlPackages = with perlPackages;
|
||||
[ AnyEvent LinuxFD SubExporter
|
||||
DataOptList ParamsUtil SubInstall
|
||||
];
|
||||
|
||||
installPhase = ''
|
||||
install -D -m644 "$src"/* -t "$out/lib/urxvt/perl"
|
||||
'';
|
||||
|
||||
meta = with stdenv.lib; {
|
||||
description = "A urxvt plugin that reloads the configuration on SIGUSR1";
|
||||
homepage = "https://maxwell.ydns.eu/git/rnhmjoj/urxvt-config-reload";
|
||||
maintainers = with maintainers; [ rnhmjoj ];
|
||||
platforms = platforms.unix;
|
||||
};
|
||||
}
|
32
src/config-print
Normal file
32
src/config-print
Normal file
@ -0,0 +1,32 @@
|
||||
#! perl
|
||||
|
||||
use v5.20;
|
||||
use strict;
|
||||
use warnings;
|
||||
no warnings "experimental";
|
||||
|
||||
our @resources = (
|
||||
qw(
|
||||
background foreground cursorColor
|
||||
pointerColor pointerColor2
|
||||
highlight borderColor
|
||||
font geometry
|
||||
),
|
||||
map { "color$_" } 0..15
|
||||
);
|
||||
|
||||
sub on_start {
|
||||
my %fallbacks = (
|
||||
borderColor => "background",
|
||||
cursorColor => "foreground");
|
||||
|
||||
for (@resources) {
|
||||
my $val = $TERM->x_resource($_);
|
||||
my $default = $TERM->x_resource($fallbacks{$_});
|
||||
if (not $val and $default){
|
||||
$val = $default
|
||||
}
|
||||
say "$_: " . $val;
|
||||
}
|
||||
exit;
|
||||
}
|
77
src/config-reload
Normal file
77
src/config-reload
Normal file
@ -0,0 +1,77 @@
|
||||
#! perl
|
||||
|
||||
use v5.20;
|
||||
use strict;
|
||||
use warnings;
|
||||
no warnings "experimental";
|
||||
|
||||
use AnyEvent;
|
||||
use Linux::FD qw(signalfd);
|
||||
use POSIX;
|
||||
use File::Basename qw(dirname);
|
||||
|
||||
my $sigset = POSIX::SigSet->new(&POSIX::SIGUSR1);
|
||||
sigprocmask(SIG_BLOCK, $sigset);
|
||||
my $sigfd = signalfd($sigset);
|
||||
my $libdir = dirname(__FILE__);
|
||||
|
||||
our @terms = ();
|
||||
|
||||
sub reload_all {
|
||||
my @lines = `urxvt --perl-lib $libdir -pe config-print 2>&1`;
|
||||
my %resource;
|
||||
for (@lines) {
|
||||
$resource{$1} = $2 if (/(.*?): (.*)/);
|
||||
}
|
||||
my $cmd = "";
|
||||
my $i = 0;
|
||||
RESOURCE:
|
||||
for (keys %resource) {
|
||||
my $key;
|
||||
given ($_) {
|
||||
$key = "4;$1" when (/color(\d+)/);
|
||||
$key = 10 when "foreground";
|
||||
$key = 11 when "background";
|
||||
$key = 12 when "cursorColor";
|
||||
$key = 13 when "pointerColor2";
|
||||
$key = 14 when "pointerColor";
|
||||
$key = 17 when "highlight";
|
||||
$key = 708 when "borderColor";
|
||||
$key = 710 when "font";
|
||||
when ("geometry") {
|
||||
if (my ($col, $row) = $resource{$_} =~ /(\d+)x(\d+)/) {
|
||||
$cmd .= "\e[8;${row};${col}t";
|
||||
}
|
||||
next RESOURCE;
|
||||
}
|
||||
default { next RESOURCE }
|
||||
}
|
||||
my $val = $resource{$_};
|
||||
$cmd .= "\e]$key;$val\a";
|
||||
}
|
||||
for (@terms) {
|
||||
$_->cmd_parse($cmd);
|
||||
}
|
||||
}
|
||||
|
||||
our $watch = AnyEvent->io (
|
||||
fh => $sigfd, # which file handle to check
|
||||
poll => "r", # which event to wait for ("r"ead data)
|
||||
cb => sub { # what callback to execute
|
||||
sysread $sigfd, my $dummy, 4096;
|
||||
reload_all;
|
||||
}
|
||||
);
|
||||
|
||||
sub on_start {
|
||||
my ($ext) = @_;
|
||||
push @terms, $TERM;
|
||||
();
|
||||
}
|
||||
|
||||
sub on_destroy {
|
||||
my ($ext) = @_;
|
||||
@terms = grep { $_ != $TERM } @terms;
|
||||
if (!@terms) { undef $watch; }
|
||||
();
|
||||
}
|
Loading…
Reference in New Issue
Block a user