Skip to content

Instantly share code, notes, and snippets.

@ablakely
Created August 25, 2022 00:57
Show Gist options
  • Save ablakely/b8540a02c08c7169c8871ac675c51d3f to your computer and use it in GitHub Desktop.
Save ablakely/b8540a02c08c7169c8871ac675c51d3f to your computer and use it in GitHub Desktop.
Irssi neofetch script
#!/usr/bin/perl -w
use strict;
use vars qw($VERSION %IRSSI);
$VERSION = "1.0";
%IRSSI = (
authors => "Aaron Blakely",
contact => 'aaron@ephasic.org',
name => 'neofetch for irssi',
license => 'GNU GPLV2'
);
use Irssi;
use Irssi::Irc;
sub do_neofetch {
my ($dest) = @_;
my $osColor = "\x030";
my $neofetchBin = "neofetch";
if ($^O =~ /msys/ || $^O =~ /MSWin32/) {
$neofetchBin = "sh neofetch --shell_version off";
}
my @neofetch = `$neofetchBin --off --title_fqdn on --cpu_temp F --distro_shorthand tiny --color_blocks off --memory_percent on --underline off|sed 's/\x1B\[[0-9;\?]*[a-zA-Z]//g'`;
for (my $i = 0; $i < $#neofetch; $i++) {
chomp $neofetch[$i];
$neofetch[$i] =~ s/\N{U+00C2}//g;
if ($neofetch[$i] =~ /(.*)\: (.*)/) {
my $t = $1;
if ($t eq "OS") {
if ($2 =~ /Debian/ || $2 =~ /Raspbian/ || $2 =~ /Red Hat Enterprise Linux/) { $osColor = "\x034"; }
elsif ($2 =~ /Arch/ || $2 =~ /Elementary/ || $2 =~ /Windows/) { $osColor = "\x0311"; }
elsif ($2 =~ /Ubuntu/) { $osColor = "\x037"; }
elsif ($2 =~ /Linux Mint/ || $2 =~ /Manjaro/) { $osColor = "\x039"; }
elsif ($2 =~ /Rocky/) { $osColor = "\x033"; }
elsif ($2 =~ /Gentoo/) { $osColor = "\x036"; }
elsif ($2 =~ /Fedora/) { $osColor = "\x0312"; }
elsif ($2 =~ /Pop\!_OS/) { $osColor = "\x0310"; }
}
$neofetch[$i] =~ s/$t/\002$osColor$t\003\002/;
}
}
$neofetch[0] =~ s/^(.*)\@//g;
$neofetch[0] = "\x02".$osColor."Hostname\003"."\x02".": ".$neofetch[0];
my $nf = join(" ", @neofetch);
$dest->command("/msg ".$dest->{name}." ".$nf);
}
sub fetch {
my ($text, $server, $dest) = @_;
if (!$server || !$server->{connected}) {
Irssi::print("Not connected to a server.");
return;
}
return unless $dest;
if ($dest->{type} eq "CHANNEL" || $dest->{type} eq "QUERY") {
do_neofetch($dest);
}
}
Irssi::command_bind("sysinfo", "fetch");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment