#!/usr/bin/perl
# Simple external log viewer for xchat, by jlh at gmx dot ch
# This code is public domain
# May 2006 Initial version 1.0
# April 2007 Fix for channel/nick names with shell meta-characters, v1.1
# May 2007 ^ -> ~ conversion, v1.2
# June 2007 Added support for all of strftime's %codes (Note that it does
# not work correctly in _all_ situation involving a '%%'. v1.3
use strict;
use warnings;
use POSIX qw(strftime);
# The $viewer variable contains the command to launch. #q or #Q will be
# replaced by the file name (properly shell escaped) to load.
# NOTE: For commands that do not fork by themselves, you must add a & at the
# end, to start a background process. Otherwise, xchat will stop
# responding until the viewer is closed.
# NOTE: use #q for normal shell escapes and #Q for double escape (which is a
# bit tricky). it's simplest if you just adapt the examples.
# simple xterm + less viewer
#my $viewer = 'xterm -e "less #Q" &';
# some VIM viewers
my $viewer = 'xterm -e "view #Q" &';
#my $viewer = "gview #q";
#my $viewer = "eview #q";
# add your own...
#my $viewer = "...";
sub irc_lc {
# the IRC specifications (RFC 1459) says (section 2.2): "Because of
# IRC's scandanavian origin, the characters {}| are considered to be
# the lower case equivalents of the characters []\, respectively. This
# is a critical issue when determining the equivalence of two
# nicknames." Thus we need our own version of 'lc'.
my $s = shift;
$s =~ tr/A-Z[]\\^/a-z{}|~/;
return $s;
}
# return the log file name for the current window
sub get_file_name {
my $mask = Xchat::get_prefs('irc_logmask');
my $channel = &irc_lc(Xchat::get_info('channel'));
my $network = Xchat::get_info('network');
my $server = Xchat::get_info('server');
$mask =~ s/\%c/$channel/g;
$mask =~ s/\%n/$network/g;
$mask =~ s/\%s/$server/g;
$mask = strftime($mask, localtime);
return Xchat::get_info('xchatdir') . '/xchatlogs/' . $mask;
}
sub viewlog {
my $v = $viewer;
my $f = &get_file_name;
my %repl = (q => $f, Q => $f);
$repl{q} =~ s/'/'\\''/g;
$repl{q} = "'$repl{q}'";
$repl{Q} =~ s/'/'\\\\''/g;
$repl{Q} = "'$repl{Q}'";
$v =~ s{#(\w)}{$repl{$1}}ge;
system($v);
return Xchat::EAT_ALL;
}
Xchat::register('External log viewer', '1.3', 'Command /viewlog lauches an external viewer for the current window');
Xchat::hook_command('viewlog', \&viewlog);DjiXas wrote:Um, how to use it?
Alchera wrote:DjiXas wrote:Um, how to use it?
Copy & paste it into a file and then load it?
"Pay per Click" links in signatures; am surprised the forum Administrator hasn't removed it already.
Khisanth wrote:Alchera wrote:"Pay per Click" links in signatures; am surprised the forum Administrator hasn't removed it already.
I don't think anyone is in the habit of clicking every link on a page.
Alchera wrote:Khisanth wrote:Alchera wrote:"Pay per Click" links in signatures; am surprised the forum Administrator hasn't removed it already.
I don't think anyone is in the habit of clicking every link on a page.
You'd be surprised how many gullible people are out there.
Users browsing this forum: No registered users and 1 guest