diff options
-rw-r--r-- | bnotify/bnotify.pl | 136 | ||||
-rw-r--r-- | fixery/README.md | 4 | ||||
-rw-r--r-- | fixery/trackbar.pl | 200 |
3 files changed, 340 insertions, 0 deletions
diff --git a/bnotify/bnotify.pl b/bnotify/bnotify.pl new file mode 100644 index 0000000..eaff6f8 --- /dev/null +++ b/bnotify/bnotify.pl @@ -0,0 +1,136 @@ +# todo: grap topic changes + +use strict; +use vars qw($VERSION %IRSSI); + +use Irssi; +$VERSION = '0.0.1'; +%IRSSI = ( + authors => 'richo', + contact => 'richo@psych0tik.net', + name => 'bnotify', + description => 'Write notifications based on who\'s talking to you, also handle some window management and tmux alerts', + url => 'http://natalya.psych0tik.net/~richo/bnotify', + license => 'GNU General Public License', + changed => '$Date: 2011-06-21 21:51:30 +1000 (Tue, 21 Jun 2011) $' +); +# Originally based on fnotify.pl 0.0.3 by Thorsten Leemhuis +# fedora@leemhuis.info +# 'http://www.leemhuis.info/files/fnotify/', +# +#-------------------------------------------------------------------- +# In parts based on knotify.pl 0.1.1 by Hugo Haas +# http://larve.net/people/hugo/2005/01/knotify.pl +# which is based on osd.pl 0.3.3 by Jeroen Coekaerts, Koenraad Heijlen +# http://www.irssi.org/scripts/scripts/osd.pl +# +# Other parts based on notify.pl from Luke Macken +# http://fedora.feedjack.org/user/918/ +# +#-------------------------------------------------------------------- + +# TODO +# Add settings for which networks to beep on + +my @alert_nets = (); +sub bnotify_init { + Irssi::settings_add_str('bnotify', 'bnotify_alert_nets', ''); + @alert_nets = split(/ /, Irssi::settings_get_str('bnotify_alert_nets')); +} + +#-------------------------------------------------------------------- +# Private message parsing +#-------------------------------------------------------------------- +# TODO +# Test to see if the privmsg went to a status window, and is from bitlbee in +# which case send it to it's own window + +sub priv_msg { + my ($server,$msg,$nick,$address,$target) = @_; + # Does this expose issues if someone includes regexp chars in their server + # tag? + if (grep(/^$server->{tag}$/, @alert_nets)) { + Irssi::command('beep'); + } + filewrite($server->{tag}.":".$nick." private"); + #Irssi::settings_set_str('autocreate_query_level', 'DCCMSGS MSGS'); +} + +#-------------------------------------------------------------------- +# Private msg windowing +#-------------------------------------------------------------------- + +sub priv_msg_winhook { + my ($server,$msg,$nick,$address,$target) = @_; + if (grep($server->{tag}, @alert_nets)) { + Irssi::settings_set_str('autocreate_query_level', 'DCCMSGS MSGS'); + } +} + +#-------------------------------------------------------------------- +# Printing hilight's +#-------------------------------------------------------------------- + +sub hilight { + my ($dest, $text, $stripped) = @_; + if ($dest->{level} & MSGLEVEL_HILIGHT) { + filewrite($dest->{server}->{tag}.":".$dest->{target}. " " .$stripped ); + } +} + +#-------------------------------------------------------------------- +# Handle Arguments +#-------------------------------------------------------------------- + +sub cmd_add { + my $net = shift; + if (not grep($net, @alert_nets)) { + push @alert_nets, $net; + Irssi::active_win->print("Added $net to alert networks."); + } else { + Irssi::active_win->print("$net already configured to alert."); + } +} + +sub cmd_del { + my $net = shift; + my @valid; + my $idx = 0; + while ($idx <= $#alert_nets) { + if (lc($alert_nets[$idx]) eq lc($net)) { + push @valid, $alert_nets[$idx]; + } + $idx++; + } + if ($#alert_nets != $#valid) { + Irssi::active_win->print("Removed $net from alert networks."); + } else { + Irssi::active_win->print("$net didn't exist in alert networks."); + } + @alert_nets = @valid; +} + +#-------------------------------------------------------------------- +# The actual printing +#-------------------------------------------------------------------- + +sub filewrite { + my ($text) = @_; + open(FILE, '>' .Irssi::get_irssi_dir() . '/fnotify'); + print FILE $text . "\n"; + close (FILE); +} + +#-------------------------------------------------------------------- +# Irssi::signal_add_last / Irssi::command_bind +#-------------------------------------------------------------------- + +Irssi::signal_add_first("message private", "priv_msg_winhook"); +Irssi::signal_add_last("message private", "priv_msg"); +Irssi::signal_add_last("print text", "hilight"); + +Irssi::command_bind('bnotify add', \&cmd_add); +Irssi::command_bind('bnotify del', \&cmd_del); +bnotify_init(); + +#- end diff --git a/fixery/README.md b/fixery/README.md index a429748..c0e48df 100644 --- a/fixery/README.md +++ b/fixery/README.md @@ -17,3 +17,7 @@ When there are some here, this will be a shiney exciting list: * **TODO** Add proper settings support * **TODO** + +* `trackbar` - Shows a trackbar with where you last read up to in a buffer + + * **TODO** Verify this works with other settings for irssi time output diff --git a/fixery/trackbar.pl b/fixery/trackbar.pl new file mode 100644 index 0000000..22d82aa --- /dev/null +++ b/fixery/trackbar.pl @@ -0,0 +1,200 @@ +# trackbar.pl +# +# This little script will do just one thing: it will draw a line each time you +# switch away from a window. This way, you always know just upto where you've +# been reading that window :) It also removes the previous drawn line, so you +# don't see double lines. +# +# Usage: +# +# The script works right out of the box, but if you want you can change +# the working by /set'ing the following variables: +# +# trackbar_string The characters to repeat to draw the bar +# trackbar_style The style for the bar, %r is red for example +# See formats.txt that came with irssi +# +# /mark is a command that will redraw the line at the bottom. However! This +# requires irssi version after 20021228. otherwise you'll get the error +# redraw: unknown command, and your screen is all goofed up :) +# +# /upgrade & buf.pl notice: This version tries to remove the trackbars before +# the upgrade is done, so buf.pl does not restore them, as they are not removeable +# afterwards by trackbar. Unfortiounatly, to make this work, trackbar and buf.pl +# need to be loaded in a specific order. Please experiment to see which order works +# for you (strangely, it differs from configuration to configuration, something I will +# try to fix in a next version) +# +# Authors: +# - Main maintainer & author: Peter 'kinlo' Leurs +# - Many thanks to Timo 'cras' Sirainen for placing me on my way +# - on-upgrade-remove-line patch by Uwe Dudenhoeffer +# +# Version history: +# 1.4: - Changed our's by my's so the irssi script header is valid +# - Removed utf-8 support. In theory, the script should work w/o any +# problems for utf-8, just set trackbar_string to a valid utf-8 character +# and everything *should* work. However, this script is being plagued by +# irssi internal bugs. The function Irssi::settings_get_str does NOT handle +# unicode strings properly, hence you will notice problems when setting the bar +# to a unicode char. For changing your bar to utf-8 symbols, read the line sub. +# 1.3: - Upgrade now removes the trackbars. +# - Some code cleanups, other defaults +# - /mark sets the line to the bottom +# 1.2: - Support for utf-8 +# - How the bar looks can now be configured with trackbar_string +# and trackbar_style +# 1.1: - Fixed bug when closing window +# 1.0: - Initial release +# +# +# Call for help! +# +# There is a trackbar version 2.0 that properly handles resizes and immediate config change +# activation. However, there is/are some bug(s) in irssi's main buffer/window code that causes +# irssi to 'forget' lines, which is ofcourse completly unaccepteable. I haven't found the time +# nor do I know the irssi's internals enough to find and fix this bug, if you want to help, please +# contact me, I'll give you a copy of the 2.0 version that will immediatly show you the problems. +# +# Known bugs: +# - if you /clear a window, it will be uncleared when returning to the window +# - UTF-8 characters in the trackbar_string doesnt work. This is an irssi bug. +# - if you resize your irssi (in xterm or so) the bar is not resized +# - changing the trackbar style is only visible after returning to a window +# however, changing style/resize takes in effect after you left the window. +# +# Whishlist/todo: +# - instead of drawing a line, just invert timestamp or something, +# to save a line (but I don't think this is possible with current irssi) +# - some pageup keybinding possibility, to scroll up upto the trackbar +# - <@coekie> kinlo: if i switch to another window, in another split window, i +# want the trackbar to go down in the previouswindow in that splitwindow :) +# - < bob_2> anyway to clear the line once the window is read? +# - < elho> kinlo: wishlist item: a string that gets prepended to the repeating pattern +# - < elho> an option to still have the timestamp in front of the bar +# - < elho> oh and an option to not draw it in the status window :P +# +# BTW: when you have feature requests, mailing a patch that works is the fastest way +# to get it added :p + +use strict; +use POSIX qw(strftime); +use 5.6.1; +use Irssi; +use Irssi::TextUI; + +my $VERSION = "1.4"; + +my %IRSSI = ( + authors => "Peter 'kinlo' Leurs", + contact => "peter\@pfoe.be", + name => "trackbar", + description => "Shows a bar where you've last read a window", + license => "GPLv2", + url => "http://www.pfoe.be/~peter/trackbar/", + changed => "Thu Feb 20 16:18:08 2003", +); + +my %config; + +Irssi::settings_add_str('trackbar', 'trackbar_string' => '-'); +$config{'trackbar_string'} = Irssi::settings_get_str('trackbar_string'); + +Irssi::settings_add_str('trackbar', 'trackbar_style' => '%K'); +$config{'trackbar_style'} = Irssi::settings_get_str('trackbar_style'); + +Irssi::signal_add( + 'setup changed' => sub { + $config{'trackbar_string'} = Irssi::settings_get_str('trackbar_string'); + $config{'trackbar_style'} = Irssi::settings_get_str('trackbar_style'); + if ($config{'trackbar_style'} =~ /(?<!%)[^%]|%%|%$/) { + Irssi::print( + "trackbar: %RWarning!%n 'trackbar_style' seems to contain " + . "printable characters. Only use format codes (read " + . "formats.txt).", MSGLEVEL_CLIENTERROR); + } + } +); + +Irssi::signal_add( + 'window changed' => sub { + my (undef, $oldwindow) = @_; + + if ($oldwindow) { + my $line = $oldwindow->view()->get_bookmark('trackbar'); + $oldwindow->view()->remove_line($line) if defined $line; + $oldwindow->print(line($oldwindow->{'width'}), MSGLEVEL_NEVER); + $oldwindow->view()->set_bookmark_bottom('trackbar'); + } + } +); + +sub line { + my $width = shift; + my $string = $config{'trackbar_string'}; + $string = '-' unless defined $string; + + # There is a bug in irssi's utf-8 handling on config file settings, as you + # can reproduce/see yourself by the following code sniplet: + # + # my $quake = pack 'U*', 8364; # EUR symbol + # Irssi::settings_add_str 'temp', 'temp_foo' => $quake; + # Irssi::print length $quake; + # # prints 1 + # Irssi::print length Irssi::settings_get_str 'temp_foo'; + # # prints 3 + # + # + # Trackbar used to have a workaround, but on recent versions of perl/irssi + # it does no longer work. Therefore, if you want your trackbar to contain + # unicode characters, uncomment the line below for a nice full line, or set + # the string to whatever char you want. + + # $string = pack('U*', 0x2500); + + + my $length = length $string; + + if ($length == 0) { + $string = '-'; + $length = 1; + } + + my $times = $width / $length; + $times = int(1 + $times) if $times != int($times); + $string =~ s/%/%%/g; + return $config{'trackbar_style'} . substr($string x $times, 0, $width); +} + +# Remove trackbars on upgrade - but this doesn't really work if the scripts are not loaded in the correct order... watch out! + +Irssi::signal_add_first( 'session save' => sub { + for my $window (Irssi::windows) { + next unless defined $window; + my $line = $window->view()->get_bookmark('trackbar'); + $window->view()->remove_line($line) if defined $line; + } + } +); + +sub cmd_mark { + my $window = Irssi::active_win(); +# return unless defined $window; + my $line = $window->view()->get_bookmark('trackbar'); + $window->view()->remove_line($line) if defined $line; + $window->print(line($window->{'width'}), MSGLEVEL_NEVER); + $window->view()->set_bookmark_bottom('trackbar'); + Irssi::command("redraw"); +} + +sub cmd_goto { + my $window = Irssi::active_win(); + my $line = $window->view()->get_bookmark('trackbar'); + # FIXME? does this work properly if they use a different date format? + my $time = strftime("%H:%M", localtime($line->{info}->{time})); + Irssi::command("GOTO $time"); +} + + +Irssi::command_bind('mark', 'cmd_mark'); +Irssi::command_bind('gototb', 'cmd_goto'); |