summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorailin-nemui2016-04-26 20:51:34 +0200
committerailin-nemui2016-04-26 20:51:34 +0200
commit0e27c2df21881ab503ebd327aa6b755e28deaef8 (patch)
treee6dc19ce643e9135287cc7cd9782e95cc01ca5fc /scripts
parent5c5d22e215f61fe43cb65e5bc4eac8f478313b5a (diff)
parent538b2c13f460213b61baa5190b88aa5eff7765e8 (diff)
downloadscripts.irssi.org-0e27c2df21881ab503ebd327aa6b755e28deaef8.tar.bz2
Merge pull request #259 from tslocum/hilightcmd
Add hilightcmd with proper shell string quoting
Diffstat (limited to 'scripts')
-rw-r--r--scripts/hilightcmd.pl53
1 files changed, 53 insertions, 0 deletions
diff --git a/scripts/hilightcmd.pl b/scripts/hilightcmd.pl
new file mode 100644
index 0000000..42585ef
--- /dev/null
+++ b/scripts/hilightcmd.pl
@@ -0,0 +1,53 @@
+#
+# 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 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;
+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",
+ 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/^\s+|\s+$//g;
+ system(named_sprintf(
+ Irssi::settings_get_str('hilightcmd_systemcmd'),
+ message => shell_quote_best_effort $stripped
+ ));
+ }
+});
+
+
+Irssi::settings_add_bool('hilightcmd', 'hilightcmd_privmsg', 1);
+Irssi::settings_add_bool('hilightcmd', 'hilightcmd_currentwin', 1);
+Irssi::settings_add_str('hilightcmd', 'hilightcmd_systemcmd', '');