aboutsummaryrefslogtreecommitdiffstats
path: root/feature-tests/easy_exec.pl
blob: d34251672ad345a2d36aaa7897491b9a58a087d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use strict;
use warnings;

# export everything.
use Irssi;
use Irssi::Irc;
use Irssi::TextUI;

use Data::Dumper;

our $VERSION = '0.1';
our %IRSSI = (
              authors     => 'shabble',
              contact     => 'shabble+irssi@metavore.org',
              name        => 'easy_exec',
              description => 'drop-in replacement for /script exec which imports'
               . ' all of the Irssi:: namespace for easier testing',
              license     => 'Public Domain',
             );

# TODO: make this more tab-complete friendly
init();

sub init {
    Irssi::command('/alias se script exec use Data::Dumper\;'
                   .' use Irssi (@Irssi::EXPORT_OK)\; $0-');
    Irssi::command('/alias sep script exec -permanent '
                   . 'use Data::Dumper\; use Irssi (@Irssi::EXPORT_OK)\; $0-');

    Irssi::signal_add_last ('complete word', 'sig_complete_word');
}

sub sig_complete_word {
    my ($strings, $window, $word, $linestart, $want_space) = @_;
    # only provide these completions if the input line is otherwise empty.
    my $cmdchars = Irssi::settings_get_str('cmdchars');
    my $quoted = quotemeta($cmdchars);
    #print "Linestart: $linestart";
    return unless ($linestart =~ /^${quoted}(?:se|sep)/);
    
    my $clean_word = $word;
    $clean_word =~ s/^"//g;
    $clean_word =~ s/"$//g;
    $clean_word =~ s/->$//g;



    my @expansions = @Irssi::EXPORT_OK;
    push @$strings,  grep { $_ =~ m/^\Q$clean_word\E/ } @expansions;
    print "Sebug: " . join(", ", @$strings);
    $$want_space = 0;


    Irssi::signal_stop() if (@$strings);
}