From 0c43cce461b9ced27adbdd6973a93adb2a859a93 Mon Sep 17 00:00:00 2001 From: ramnes Date: Thu, 3 Mar 2016 17:18:21 +0100 Subject: Add hilightcmd --- scripts/hilightcmd.pl | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 scripts/hilightcmd.pl (limited to 'scripts') diff --git a/scripts/hilightcmd.pl b/scripts/hilightcmd.pl new file mode 100644 index 0000000..b17f624 --- /dev/null +++ b/scripts/hilightcmd.pl @@ -0,0 +1,48 @@ +# +# Call a custom system command when receiving a hilight. +# Originally based on hilightwin.pl work and djcraven5's idea for making remote +# computer beep through ssh. +# +# Example of use, assuming you got a ssh and beep on your remote: +# /set hilightcmd_systemcmd ssh user@host beep & +# + +use Irssi; +use POSIX; +use vars qw($VERSION %IRSSI); +use Text::Sprintf::Named qw(named_sprintf); + +$VERSION = "0.1"; +%IRSSI = (authors => "Guillaume Gelin", + contact => "contact\@ramnes.eu", + name => "hilightcmd", + description => "Call a system command when receiving a hilight", + license => "GNU GPLv3", + url => "https://github.com/ramnes/hilightcmd"); + + +Irssi::signal_add('print text' => sub { + my ($dest, $text, $stripped) = @_; + my $opt = MSGLEVEL_HILIGHT; + + if (Irssi::settings_get_bool('hilightcmd_privmsg')) { + $opt = MSGLEVEL_HILIGHT|MSGLEVEL_MSGS; + } + + if (($dest->{level} & ($opt)) + && ($dest->{level} & MSGLEVEL_NOHILIGHT) == 0 + && (Irssi::active_win()->{refnum} != $dest->{window}->{refnum} + || Irssi::settings_get_bool('hilightcmd_currentwin'))) { + + $stripped =~ s/"/\\"/g; + system(named_sprintf( + Irssi::settings_get_str('hilightcmd_systemcmd'), + message => $stripped + )); + } +}); + + +Irssi::settings_add_bool('hilightcmd', 'hilightcmd_privmsg', 1); +Irssi::settings_add_bool('hilightcmd', 'hilightcmd_currentwin', 1); +Irssi::settings_add_str('hilightcmd', 'hilightcmd_systemcmd', ''); -- cgit v1.2.3 From 39e19c5e9dedd38aaf23ff5cc11d014108175a1b Mon Sep 17 00:00:00 2001 From: ramnes Date: Fri, 4 Mar 2016 15:06:09 +0100 Subject: Use strict --- scripts/hilightcmd.pl | 1 + 1 file changed, 1 insertion(+) (limited to 'scripts') diff --git a/scripts/hilightcmd.pl b/scripts/hilightcmd.pl index b17f624..a234082 100644 --- a/scripts/hilightcmd.pl +++ b/scripts/hilightcmd.pl @@ -7,6 +7,7 @@ # /set hilightcmd_systemcmd ssh user@host beep & # +use strict; use Irssi; use POSIX; use vars qw($VERSION %IRSSI); -- cgit v1.2.3 From fa39bc3a92fd2a8b7efdcbb7ae326e3227a9e4f3 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Mon, 25 Apr 2016 19:51:28 -0700 Subject: Quote message before passing to shell --- scripts/hilightcmd.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/hilightcmd.pl b/scripts/hilightcmd.pl index a234082..c2c8295 100644 --- a/scripts/hilightcmd.pl +++ b/scripts/hilightcmd.pl @@ -12,6 +12,7 @@ use Irssi; use POSIX; use vars qw($VERSION %IRSSI); use Text::Sprintf::Named qw(named_sprintf); +use String::ShellQuote qw(shell_quote_best_effort); $VERSION = "0.1"; %IRSSI = (authors => "Guillaume Gelin", @@ -38,7 +39,7 @@ Irssi::signal_add('print text' => sub { $stripped =~ s/"/\\"/g; system(named_sprintf( Irssi::settings_get_str('hilightcmd_systemcmd'), - message => $stripped + message => shell_quote_best_effort $stripped )); } }); -- cgit v1.2.3 From 538b2c13f460213b61baa5190b88aa5eff7765e8 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Tue, 26 Apr 2016 11:41:22 -0700 Subject: Trim whitespace from hilighted text and improve script usage examples --- scripts/hilightcmd.pl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/hilightcmd.pl b/scripts/hilightcmd.pl index c2c8295..42585ef 100644 --- a/scripts/hilightcmd.pl +++ b/scripts/hilightcmd.pl @@ -3,8 +3,11 @@ # Originally based on hilightwin.pl work and djcraven5's idea for making remote # computer beep through ssh. # -# Example of use, assuming you got a ssh and beep on your remote: -# /set hilightcmd_systemcmd ssh user@host beep & +# Example of use, assuming you have ssh and beep on your remote: +# /set hilightcmd_systemcmd ssh user@host beep & +# +# The hilighted text may be passed as a quoted string: +# /set hilightcmd_systemcmd printf "%s\n" %(message)s >> ~/hilights # use strict; @@ -36,7 +39,7 @@ Irssi::signal_add('print text' => sub { && (Irssi::active_win()->{refnum} != $dest->{window}->{refnum} || Irssi::settings_get_bool('hilightcmd_currentwin'))) { - $stripped =~ s/"/\\"/g; + $stripped =~ s/^\s+|\s+$//g; system(named_sprintf( Irssi::settings_get_str('hilightcmd_systemcmd'), message => shell_quote_best_effort $stripped -- cgit v1.2.3