irssi: dynamic-nick.pl — set default nick to `|<hostname> at startup

Autorun script so the same drunkendotfiles deploy gives each host a
distinctive nick without per-host config hand-edits. Trims FQDNs to
the short hostname before composing. Static 'nick = "`"' in
config stays as a fallback if the script ever fails to load.
This commit is contained in:
2026-04-21 09:07:09 -07:00
parent 6f86285f71
commit 92b9e0ec99

View File

@@ -0,0 +1,34 @@
#
# dynamic-nick.pl — sets the irssi default nick to `|<hostname> at startup,
# so the same dotfiles give each machine its own distinctive nick without
# having to hand-edit the config per host.
#
# Drops into ~/.irssi/scripts/autorun/, loads on irssi start.
#
use strict;
use warnings;
use vars qw($VERSION %IRSSI);
use Irssi;
use Sys::Hostname qw(hostname);
$VERSION = '0.1';
%IRSSI = (
authors => 'dissimulo',
contact => 'connect+gitea@dustin-williams.com',
name => 'dynamic-nick',
description => 'Set the default nick to `|<hostname> at startup.',
license => 'MIT',
);
sub set_dynamic_nick {
my $host = hostname();
# trim anything past the first dot — some systems return FQDNs, which
# are longer than most IRCd nick limits (typically 1630 chars).
$host =~ s/\..*$//;
my $nick = '`|' . $host;
Irssi::command("^set nick $nick");
Irssi::print("dynamic-nick: default nick set to $nick", MSGLEVEL_CLIENTCRAP);
}
set_dynamic_nick();