summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/autoclearinput.pl77
-rw-r--r--scripts/hipchat_complete.pl20
-rw-r--r--scripts/spotify.pl11
-rw-r--r--scripts/tmux_away.pl181
-rw-r--r--scripts/u.pl13
-rw-r--r--scripts/winnum.pl41
6 files changed, 323 insertions, 20 deletions
diff --git a/scripts/autoclearinput.pl b/scripts/autoclearinput.pl
new file mode 100644
index 0000000..f01df5d
--- /dev/null
+++ b/scripts/autoclearinput.pl
@@ -0,0 +1,77 @@
+#
+# autoclearinput.pl
+# Automatically clears pending input when you are away.
+#
+#
+# Settings:
+# /SET autoclear_sec <seconds> (0 to disable, 30 by default)
+#
+# Commands:
+# /AUTOCLEARED, /CLEARED Retrieve the last cleared line of input
+#
+
+use strict;
+use vars qw($VERSION %IRSSI);
+
+$VERSION = '1.0.1';
+%IRSSI = (
+ authors => 'Trevor "tee" Slocum',
+ contact => 'tslocum@gmail.com',
+ name => 'AutoClearInput',
+ description => 'Automatically clears pending input when you are away.',
+ license => 'GPLv3',
+ url => 'https://github.com/tslocum/irssi-scripts',
+ changed => '2014-05-13'
+);
+
+my ($autoclear_tag, $autoclear_last_input);
+
+sub autoclear_key_pressed {
+ return if (Irssi::settings_get_int("autoclear_sec") <= 0);
+
+ if (defined($autoclear_tag)) {
+ Irssi::timeout_remove($autoclear_tag);
+ }
+
+ $autoclear_tag = Irssi::timeout_add_once(Irssi::settings_get_int("autoclear_sec") * 1000, "autoclear_timeout", "");
+}
+
+sub autoclear_timeout {
+ return if (Irssi::settings_get_int("autoclear_sec") <= 0);
+
+ my $autoclear_current_input = Irssi::parse_special('$L');
+ $autoclear_current_input =~ s/^\s+//;
+ $autoclear_current_input =~ s/\s+$//;
+ if ($autoclear_current_input ne "") {
+ $autoclear_last_input = Irssi::parse_special('$L');
+ }
+
+ Irssi::gui_input_set("");
+}
+
+sub autoclear_retrieve {
+ if (defined($autoclear_last_input)) {
+ Irssi::timeout_add_once(50, "autoclear_retrieve_workaround", "");
+ } else {
+ Irssi::print($IRSSI{name} . ': No input has been cleared yet.');
+ }
+}
+
+sub autoclear_retrieve_workaround {
+ return if (!defined($autoclear_last_input));
+
+ Irssi::gui_input_set($autoclear_last_input);
+ Irssi::gui_input_set_pos(length($autoclear_last_input));
+}
+
+Irssi::settings_add_int("misc", "autoclear_sec", 30);
+Irssi::signal_add_last("gui key pressed", "autoclear_key_pressed");
+Irssi::command_bind("autocleared", "autoclear_retrieve");
+Irssi::command_bind("cleared", "autoclear_retrieve");
+
+print $IRSSI{name} . ': v' . $VERSION . ' loaded. Pending input ' .
+ (Irssi::settings_get_int("autoclear_sec") > 0
+ ? ('will be cleared after %9' . Irssi::settings_get_int("autoclear_sec") . ' seconds%9 of idling.')
+ : 'clearing is currently %9disabled%9.');
+print $IRSSI{name} . ': Configure this delay with: /SET autoclear_sec <seconds> [0 to disable]';
+print $IRSSI{name} . ': Retrieve the last cleared line of input with: /CLEARED';
diff --git a/scripts/hipchat_complete.pl b/scripts/hipchat_complete.pl
index 094b9a6..54a3c52 100644
--- a/scripts/hipchat_complete.pl
+++ b/scripts/hipchat_complete.pl
@@ -1,4 +1,5 @@
# hipchat_complete.pl - (c) 2013 John Morrissey <jwm@horde.net>
+# (c) 2014 Brock Wilcox <awwaiid@thelackthereof.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
@@ -46,11 +47,11 @@
# To use
# ======
#
-# 1. Install the HTTP::Message, JSON, and LWP Perl modules.
+# 1. Install the WebService::HipChat module from CPAN.
#
# 2. /script load hipchat_completion.pl
#
-# 3. Get a Hipchat auth token (hipchat.com -> Account settings -> API
+# 3. Get a Hipchat auth v2 token (hipchat.com -> Account settings -> API
# access). In irssi:
#
# /set hipchat_auth_token some-hex-value
@@ -63,12 +64,10 @@
use strict;
-use HTTP::Request;
use Irssi;
-use JSON;
-use LWP::UserAgent;
+use WebService::HipChat;
-my $VERSION = '1.0';
+my $VERSION = '2.0';
my %IRSSI = (
authors => 'John Morrissey',
contact => 'jwm@horde.net',
@@ -81,18 +80,13 @@ my %NICK_TO_MENTION;
my $LAST_MAP_UPDATED = 0;
sub get_hipchat_people {
- my $ua = LWP::UserAgent->new;
- $ua->timeout(5);
-
my $auth_token = Irssi::settings_get_str('hipchat_auth_token');
if (!$auth_token) {
return;
}
- my $r = HTTP::Request->new('GET',
- "https://api.hipchat.com/v1/users/list?auth_token=$auth_token");
- my $response = $ua->request($r);
+ my $hc = WebService::HipChat->new(auth_token => $auth_token);
- my $hipchat_users = from_json($response->decoded_content)->{users};
+ my $hipchat_users = $hc->get_users->{items};
foreach my $user (@{$hipchat_users}) {
my $name = $user->{name};
$name =~ s/[^A-Za-z]//g;
diff --git a/scripts/spotify.pl b/scripts/spotify.pl
index 92f82e4..607b44a 100644
--- a/scripts/spotify.pl
+++ b/scripts/spotify.pl
@@ -18,7 +18,7 @@
use strict;
use vars qw($VERSION %IRSSI);
-$VERSION = '1.0';
+$VERSION = '1.1';
%IRSSI = (
authors => 'Örjan Persson',
contact => 'o@42mm.org',
@@ -413,10 +413,15 @@ sub spotify_lookup {
my $writer = shift;
my ($uri, $manual) = @{$_[0]};
+ # Remove any leading whitespace and trailing whitespace and dots
$uri =~ s/^\s+//g;
$uri =~ s/[\s\.]+$//g;
- my $u = URI->new($uri);
- my @parts = split /[\/:]/, URI->new($uri)->path;
+
+ # Unify how we look at the path, removing leading / to match how path looks
+ # for URIs with : where the path never starts with a :.
+ my $u = URI->new($uri)->path;
+ $u =~ s/^\///;
+ my @parts = split /[\/:]/, $u;
my $path;
my $auth;
diff --git a/scripts/tmux_away.pl b/scripts/tmux_away.pl
new file mode 100644
index 0000000..a86b0d5
--- /dev/null
+++ b/scripts/tmux_away.pl
@@ -0,0 +1,181 @@
+use Irssi;
+use strict;
+use FileHandle;
+
+use vars qw($VERSION %IRSSI);
+
+$VERSION = "2.0";
+%IRSSI = (
+ authors => 'jcv',
+ name => 'tmux_away',
+ description => 'set (un)away if tmux session is attached/detached',
+ license => 'GPL v2',
+ url => 'http://www.netpurgatory.com/tmux_away.html',
+);
+
+# tmux_away irssi module
+#
+# Written by Colin Didier <cdidier@cybione.org> and heavily based on
+# screen_away irssi module version 0.9.7.1 written by Andreas 'ads' Scherbaum
+# <ads@ufp.de>.
+#
+# Updated by John C. Vernaleo <john@netpurgatory.com> to handle tmux with
+# named sessions and other code cleanup and forked as version 2.0.
+#
+# usage:
+#
+# put this script into your autorun directory and/or load it with
+# /SCRIPT LOAD <name>
+#
+# there are 5 settings available:
+#
+# /set tmux_away_active ON/OFF/TOGGLE
+# /set tmux_away_repeat <integer>
+# /set tmux_away_message <string>
+# /set tmux_away_window <string>
+# /set tmux_away_nick <string>
+#
+# active means that you will be only set away/unaway, if this
+# flag is set, default is ON
+# repeat is the number of seconds, after the script will check the
+# tmux session status again, default is 5 seconds
+# message is the away message sent to the server, default: not here ...
+# window is a window number or name, if set, the script will switch
+# to this window, if it sets you away, default is '1'
+# nick is the new nick, if the script goes away
+# will only be used it not empty
+
+
+# variables
+my $timer_name = undef;
+my $away_status = 0;
+my %old_nicks = ();
+my %away = ();
+
+# Register formats
+Irssi::theme_register(
+[
+ 'tmux_away_crap',
+ '{line_start}{hilight ' . $IRSSI{'name'} . ':} $0'
+]);
+
+# try to find out if we are running in a tmux session
+# (see if $ENV{TMUX} is set)
+if (!defined($ENV{TMUX})) {
+ # just return, we will never be called again
+ Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'tmux_away_crap',
+ "no tmux session!");
+ return;
+}
+
+my @args_env = split(',', $ENV{TMUX});
+
+# Get session name. Must be connected for this to work, but since this either
+# happens at startup or based on user command, should be okay.
+my $tmux_session = `tmux display-message -p '#S'`;
+chomp($tmux_session);
+
+# register config variables
+Irssi::settings_add_bool('misc', $IRSSI{'name'} . '_active', 1);
+Irssi::settings_add_int('misc', $IRSSI{'name'} . '_repeat', 5);
+Irssi::settings_add_str('misc', $IRSSI{'name'} . '_message', "not here...");
+Irssi::settings_add_str('misc', $IRSSI{'name'} . '_window', "1");
+Irssi::settings_add_str('misc', $IRSSI{'name'} . '_nick', "");
+
+
+# check, set or reset the away status
+sub tmux_away {
+ my ($status, @res);
+
+ # only run, if activated
+ if (Irssi::settings_get_bool($IRSSI{'name'} . '_active') != 1) {
+ $away_status = 0;
+ } else {
+ if ($away_status == 0) {
+ # display init message at first time
+ Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'tmux_away_crap',
+ "activating $IRSSI{'name'} (interval: " . Irssi::settings_get_int($IRSSI{'name'} . '_repeat') . " seconds)");
+ $away_status = 2;
+ }
+
+ # get actual tmux session status
+ @res = `tmux list-clients -t $tmux_session`;
+ if (@res[0] =~ /^failed to connect to server/) {
+ Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'tmux_away_crap',
+ "error getting tmux session status.");
+ return;
+ }
+ $status = 1; # away, assumes the session is detached
+ if ($#res != -1) {
+ $status = 2; # unaway
+ }
+
+ # unaway -> away
+ if ($status == 1 and $away_status != 1) {
+ if (length(Irssi::settings_get_str($IRSSI{'name'} . '_window')) > 0) {
+ # if length of window is greater then 0, make this window active
+ Irssi::command('window goto ' . Irssi::settings_get_str($IRSSI{'name'} . '_window'));
+ }
+ Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'tmux_away_crap', "Set away");
+ my $message = Irssi::settings_get_str($IRSSI{'name'} . '_message');
+ if (length($message) == 0) {
+ # we have to set a message or we wouldnt go away
+ $message = "not here ...";
+ }
+ foreach (Irssi::servers()) {
+ if (!$_->{usermode_away}) {
+ # user isn't yet away
+ $away{$_->{'tag'}} = 0;
+ $_->command("AWAY " . ($_->{chat_type} ne 'SILC' ? "-one " : "") . "$message");
+ if ($_->{chat_type} ne 'XMPP' and length(Irssi::settings_get_str($IRSSI{'name'} . '_nick')) > 0) {
+ # only change if actual nick isn't already the away nick
+ if (Irssi::settings_get_str($IRSSI{'name'} . '_nick') ne $_->{nick}) {
+ # keep old nick
+ $old_nicks{$_->{'tag'}} = $_->{nick};
+ # set new nick
+ $_->command("NICK " . Irssi::settings_get_str($IRSSI{'name'} . '_nick'));
+ }
+ }
+ } else {
+ # user is already away, remember this
+ $away{$_->{'tag'}} = 1;
+ }
+ }
+ $away_status = $status;
+
+ # away -> unaway
+ } elsif ($status == 2 and $away_status != 2) {
+ # unset away
+ Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'tmux_away_crap', "Reset away");
+ foreach (Irssi::servers()) {
+ if ($away{$_->{'tag'}} == 1) {
+ # user was already away, don't reset away
+ $away{$_->{'tag'}} = 0;
+ next;
+ }
+ $_->command("AWAY" . (($_->{chat_type} ne 'SILC') ? " -one" : "")) if ($_->{usermode_away});
+ if ($_->{chat_type} ne 'XMPP' and defined($old_nicks{$_->{'tag'}}) and length($old_nicks{$_->{'tag'}}) > 0) {
+ # set old nick
+ $_->command("NICK " . $old_nicks{$_->{'tag'}});
+ $old_nicks{$_->{'tag'}} = "";
+ }
+ }
+ $away_status = $status;
+ }
+ }
+ # but everytimes install a new timer
+ register_tmux_away_timer();
+ return 0;
+}
+
+# remove old timer and install a new one
+sub register_tmux_away_timer {
+ if (defined($timer_name)) {
+ Irssi::timeout_remove($timer_name);
+ }
+ # add new timer with new timeout (maybe the timeout has been changed)
+ $timer_name = Irssi::timeout_add(Irssi::settings_get_int($IRSSI{'name'} . '_repeat') * 1000, 'tmux_away', '');
+}
+
+# init process
+tmux_away();
diff --git a/scripts/u.pl b/scripts/u.pl
index a552da7..e785c76 100644
--- a/scripts/u.pl
+++ b/scripts/u.pl
@@ -1,7 +1,7 @@
use vars qw($VERSION %IRSSI);
use Irssi 20020120;
-$VERSION = "1.2";
+$VERSION = "1.3";
%IRSSI = (
authors => "Michiel",
contact => "michiel\@dotgeek.org",
@@ -12,7 +12,6 @@ $VERSION = "1.2";
changed => "Thu Jun 3 11:04:27 CEST 2004",
);
-
sub cmd_u
{
my ($data, $server, $channel) = @_;
@@ -21,12 +20,18 @@ sub cmd_u
my $msg;
my $match;
my $nick;
-
+
if ($channel->{type} ne "CHANNEL")
{
Irssi::print("You are not on a channel");
return;
}
+
+ eval { /$data/ } ;
+ if ($@) {
+ Irssi::print("Not a valid regexp given.",MSGLEVEL_CLIENTERROR);
+ return;
+ }
@nicks = $channel->nicks();
@@ -60,7 +65,7 @@ sub cmd_u
}
$match = $nick->{nick}.'!'.$nick->{host}; # For regexp matching
-
+
$channel->print($msg) if $match =~ /$data/i;
}
diff --git a/scripts/winnum.pl b/scripts/winnum.pl
new file mode 100644
index 0000000..e9ed0bc
--- /dev/null
+++ b/scripts/winnum.pl
@@ -0,0 +1,41 @@
+#
+# winnum.pl
+# Goto a window by its reference number with /##
+#
+#
+# Commands:
+# /<window #> Go to window
+#
+
+use strict;
+use vars qw($VERSION %IRSSI);
+
+$VERSION = '1.0.0';
+%IRSSI = (
+ authors => 'Trevor "tee" Slocum',
+ contact => 'tslocum@gmail.com',
+ name => 'WinNum',
+ description => 'Goto a window by its reference number with /##',
+ license => 'GPLv3',
+ url => 'https://github.com/tslocum/irssi-scripts',
+ changed => '2014-05-01'
+);
+
+sub winnum_default_command {
+ my ($command, $server) = @_;
+
+ $command =~ s/^\s+//;
+ $command =~ s/\s+$//;
+ my $winnum = ($command =~ /(\w+)/)[0];
+
+ if ($winnum =~ /^\d+$/) {
+ my $window = Irssi::window_find_refnum($winnum);
+ $window->set_active if $window;
+
+ Irssi::signal_stop();
+ }
+}
+
+Irssi::signal_add_first("default command", "winnum_default_command");
+
+print $IRSSI{name} . ': v' . $VERSION . ' loaded. Enter %9/<window #>%9 to goto a window.';