-
Notifications
You must be signed in to change notification settings - Fork 235
/
scriptsave.pl
75 lines (69 loc) · 1.87 KB
/
scriptsave.pl
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use strict;
use warnings;
use Irssi;
use File::Basename;
use vars qw($VERSION %IRSSI);
$VERSION = '0.2';
%IRSSI = (
authors => 'lasers',
contact => 'lasers on freenode',
name => 'scriptsave',
description => 'Loads scripts from file instead of autorun directory',
license => 'WTFPL',
);
# ──── USAGE ────
# Outside irssi:
# Remove ~/.irssi/scripts/autorun
# Add "script load scriptsave" to ~/.irssi/startup
#
# Inside irssi:
# /help script
# /script save
#
# ──── NOTE ────
# Scripts will be saved to ~/.irssi/config.scriptsave
#
# ──── LIMITATION #1 ────
# This script will not work with scripts with a dash
# in their filenames. Remember to omit them or replace
# them with an underscore when adding new scripts.
# ✖ Script-name.pl
# ✔ Script_name.pl
# ✔ Scriptname.pl
#
# ──── LIMITATION #2 ────
# This script will not work with /script exec -permanent
my $name = basename(__FILE__);
$name =~ s/\.[^.]+$//;
my $lst = Irssi::get_irssi_dir()."/config.scriptsave";
sub cmd_load_scripts(){
if (open(my $f, '<:encoding(UTF-8)', $lst)){
while (my $line = <$f>) {
chomp $line;
if ($line ne $name){
Irssi::command('script load '.$line);
}
}
}
}
sub cmd_save_scripts {
unlink $lst;
foreach (sort grep(s/::$//, keys %Irssi::Script::)){
open(my $fh, ">>", $lst);
if (($_ ne $name) && ($_ !~ m/data+(\d)/)){
print $fh "$_\n";
}
close $fh;
}
Irssi::print ("Scripts saved to $lst");
}
sub cmd_print_help() {
my ($args) = @_;
if ($args =~ /^script( load)? *$/i){
my $help = "\n/SCRIPT SAVE saves the list of currently loaded scripts to the file.";
Irssi::print($help, MSGLEVEL_CLIENTCRAP);
}
}
cmd_load_scripts;
Irssi::command_bind('script save', 'cmd_save_scripts');
Irssi::command_bind_last('help', 'cmd_print_help');