Skip to content

Instantly share code, notes, and snippets.

@nathanharper
Created September 27, 2012 21:37
Show Gist options
  • Save nathanharper/3796615 to your computer and use it in GitHub Desktop.
Save nathanharper/3796615 to your computer and use it in GitHub Desktop.
Irssi script to convert URLs in messages to TinyURL
# I use iTerm2, which enables clicking to open URLs, but if the line wraps in the middle of one,
# iTerm2 does not recognize this. This script greatly decreases the chance that long URLs will wrap
# by using the Tiny URL API to shorten the URL. The script intercepts the message, and converts all URLs in place.
#
# DEPENDENCIES: must have the cURL command line utilities installed.
# DISCLAIMER: I don't use Windows, I don't know how cURL works on Windows, and I don't guarantee this will work. If it does, great!
use strict;
use Irssi;
use vars qw($VERSION %IRSSI);
$VERSION="0.1";
%IRSSI =
(
authors => "nathan (nathan\@reflexionsdata.com)",
contact => "nathan\@reflexionsdata.com",
name => "Tiny URL",
description => "Converts URLs from incoming messages to Tiny URL.",
license => "GNU GPL",
url => "none",
);
sub tinify {
my ($server, $msg, @rest) = @_;
if (my @urls = ($msg=~/\bhttps?:\/\/[^\s']+(?:\s|$)/g)) {
foreach (@urls) {
my $tiny_url = `curl -fs 'http://tinyurl.com/api-create.php?url=$_'`;
$msg =~ s/\Q$_\E/$tiny_url/g;
}
}
Irssi::signal_continue($server, $msg, @rest);
}
Irssi::signal_add_first "message private", "tinify";
Irssi::signal_add_first "message public", "tinify";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment