#!/usr/bin/perl

# explanation: ./URL_ref.pl

use strict;
use warnings;
use Irssi;

sub cmd_echo_URL {
    my ($data, $server, $win) = @_;

    # files
    my $home_path = $ENV{"HOME"};
    my $script_path = "$home_path/.irssi/scripts";
    my $URL_file = "$script_path/.irssi_URLs.txt";
    my $current_URL = "$script_path/.current_URL.txt";

    # save reference
    my $line_write = "$data"."w";
    system("sed -n '$line_write $current_URL' $URL_file");

    # echo URL
    my $line_print = "$data"."p";
    my $URL = qx{ sed -n $line_print $URL_file };
    $server->command("echo -current  Saved: $URL");
}

Irssi::command_bind('elink', 'cmd_echo_URL');
