-- -- Copyright (c) 2010 by James Campos -- Copyright (c) 2009 by FlashCode -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 3 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -- -- -- Launch external commands for signals. -- (this script requires WeeChat 0.3.0 or newer) -- -- History: -- -- 2010-05-27, James Campos : -- version 0.3: lua rewrite, add access to signal_data -- 2009-05-02, FlashCode : -- version 0.2: sync with last API changes -- 2009-02-03, FlashCode : -- version 0.1: initial release -- version = "0.3" command_suffix = " &" weechat.register("launcher", "FlashCode ", version, "GPL3", "Launch external commands for signals", "", ""); weechat.hook_command("launcher", "Associate external commands to signals", "[signal command] | [-del signal]", " signal: name of signal, may begin or end with \"*\" to catch many signals (common signals are: \"weechat_highlight\", \"weechat_pv\")\n" .."command: command to launch when this signal is received (see below)\n" .." -del: delete commande associated to a signal\n\n" .."Notes about command:\n" .."- you can separate many commands with \";\"\n" .."- string \"\$signal_data\" is replaced by signal data, enclosed by quotes.\n\n" .."Examples:\n" .." play a sound for highlights:\n" .." /launcher weechat_highlight alsaplay -i text ~/sound_highlight.wav\n" .." play a sound for private messages:\n" .." /launcher weechat_pv alsaplay -i text ~/sound_pv.wav\n" .." delete command for signal \"weechat_highlight\":\n" .." /launcher -del weechat_highlight\n" .." show messages in popups (requires Awesome):\n" .." /launcher weechat_highlight echo '$signal_data' | sed 's/\\t/\" \"/' | xargs notify-send\n\n" .."For advanced users: it's possible to change commands with /set command:\n" .." /set plugins.var.lua.launcher.signal.weechat_highlight \"my command here\"", "", "launcher_cmd", ""); weechat.hook_signal("*", "signal", ""); function launcher_cmd(data, buffer, args) a, b = string.match(args, "([^ ]+) (.*)") if a then if a == "-del" then local signal = b command = weechat.config_get_plugin("signal." .. signal) if command then weechat.config_unset_plugin("signal." .. signal) weechat.print("", "launcher: command deleted for signal " .. signal) else weechat.print("", weechat.prefix("error").."launcher: command not defined for signal \""..signal.."\"") end else local signal = a command = b match = string.match(command, "^\"(.*)\"$") if match then command = match end weechat.config_set_plugin("signal."..signal, command) weechat.print("", "launcher: signal \""..signal.."\" --> command: \""..command.."\"") end else weechat.command(buffer, "/set plugins.var.lua.launcher.*"); end return weechat.WEECHAT_RC_OK; end function signal(data, signal, signal_data) command = weechat.config_get_plugin("signal."..signal); if command ~= "" then signal_data = string.format("%q", signal_data) command = string.gsub(command, "\$signal_data", signal_data) if command then os.execute(command .. command_suffix) end end return weechat.WEECHAT_RC_OK; end