Date display for Irssi

Irssi shows the time just fine, but it lacks the date. For users like myself who use a cut-down window manager, this information isn't available anywhere else, either.

Background

When I switched from the Gnome Desktop to ion2, I loved it! However, I quickly became frustrated that I couldn't take a quick glace at Gnome's taskbar to find out the date when I needed to write it. I settled with using cal and date for a while, but I disliked having to type a command, because I'm a lazy sod.

I always have an irssi session running in screen on another computer, which I always connect to from my usual one. This made it ideal to add a date into, for my viewing pleasure.

Method

I took a look on irssi.org's scripts section, but couldn't find anything that'd display the date for me. Annoying. Having said that, this one isn't there either so maybe there's a whole load of different versions of date displays for irssi out there. Either way, I couldn't find one.

I don't know Perl, so it was hacking time. Fortunately, there were a couple of other scripts there which I could bodge to suit my needs, and thanks to the wonderful GPL I was legally allowed to do so, as well! (Provided this code gets released as GPL too, which I've no problem with.)

Solution

Right-click here and choose "Save Link As..." (or similar) to download the source code. Rename it from date.txt to date.pl

This solution has no bells and whistles. It checks for a new date every 5 seconds, and display the date in UK dd/mm/yyyy format. Changing this (if required) is left as an exercise to the reader, and should be trivial.

Installation

Move the script to your irssi's script directory (usually ~/.irssi/scripts/ or .irssi/scripts/autorun if you want the script to run at irssi startup).

In irssi, type /script load date.pl (or autorun/date.pl), then /statusbar topic add date to (for example) add the date display to the topic bar. Replace 'topic' with 'window' for the main irssi status bar, and see /help statusbar for information on fine-tuning the location.

Source

use Irssi 20020101.0250 ();
$VERSION = "1.16";
%IRSSI = (
    authors     => 'Nick Murdoch',
    contact     => 'nivan@nivan.net',
    name        => 'date',
    description => 'Adds the date as a statusbar item',
    license     => 'GNU GPLv2',
    url         => 'http://nivan.net/',
);

use Irssi::TextUI;

sub date ($$) {
	
	my ($sbitem, $get_size_only) = @_;
	

	($Sec,$Min,$Hour,$Day,$Month,$Year,$Week_Day) = (localtime); 
	$Year -= 100;
	$Month += 1;
	# Pad <10 with a 0
	if ($Day < 10) { $Day = "0".$Day; }
	if ($Month < 10) { $Month = "0".$Month; }
	if ($Year < 10) { $Year = "0".$Year; }

	my $format = sprintf("{sb %s/%s/%s}", $Day,$Month,$Year);
	$sbitem->default_handler($get_size_only, $format, undef, 1);
}


sub refreshdate {
	
	Irssi::statusbar_items_redraw("date");
}
	
Irssi::statusbar_item_register('date', undef, 'date');
Irssi::timeout_add(5000, "refreshdate", undef);




Last Modified: Monday, 25-Jun-2007 14:54:32 BST