Last active
April 16, 2016 23:17
-
-
Save tpruvot/01b364509a6695e5e46aad532fc7f9b0 to your computer and use it in GitHub Desktop.
Autoload plugins in addons sub folders, place this script in HexChat\addons
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Name: autoload.pl | |
# Version: 1.2 | |
# Author: tpruvot@github | |
# Date: 2016-04-17 | |
# Description: Autoload plugins in addons sub folders, place this script in HexChat\addons | |
use Xchat qw (:all); | |
register('AutoLoad', '1.2', 'Plugin Auto Loader', \&auto_unload); | |
my $configdir = get_info('configdir'); | |
my $addons_path = "$configdir/addons"; | |
$addons_path =~ s/\\/\//g; | |
# Plugin list to load on hexchat startup | |
my @plugins_list = ( | |
"$addons_path/perl/randslappy/randslappy.pl", | |
"$addons_path/python/at/at.py", | |
); | |
# Also allow to load a list from a text file | |
# Note: you can use $addons_path variable in the file | |
my $conf = "$addons_path/autoload.txt"; | |
open my $handle, '<', $conf; | |
if ($handle >= 0) { | |
chomp(my @lines = <$handle>); | |
close $handle; | |
push @plugins_list, @lines; | |
} | |
my @plugins_loaded = (); | |
sub extract_filetype { | |
my $path = $_[0]; | |
my @parts = split '\.', $path; | |
return (pop @parts); | |
} | |
sub extract_filename { | |
my $path = $_[0]; | |
my @parts = split '/', $path; | |
return (pop @parts); | |
} | |
# Load plugins | |
for my $plugin (@plugins_list) { | |
$plugin =~ s/\$addons_path/$addons_path/; | |
my $ext = extract_filetype($plugin); | |
my $res = command("load $plugin") if ($ext eq 'pl' && -e $plugin); | |
$res |= command("py load $plugin") if ($ext eq 'py' && -e $plugin); | |
push @plugins_loaded, $plugin if ($res); | |
# Xchat::printf("AutoLoad $plugin"); | |
} | |
# Cleanup | |
sub auto_unload { | |
for my $plugin (@plugins_loaded) { | |
my $fn = extract_filename($plugin); | |
my $ext = extract_filetype($fn); | |
command("unload $fn") if ($ext eq 'pl'); | |
command("py unload $fn") if ($ext eq 'py'); | |
} | |
Xchat::printf("AutoLoad unloaded"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment