diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2021-04-06 18:37:22 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2021-04-06 18:37:22 +0200 |
commit | fae9bdf8f8cf51eb07602dc8f6633e380ff94b20 (patch) | |
tree | 43bbc457789d6afbdc9414d3dd990032e96c242c /src/plugins | |
parent | 3bf585ba04e7ff4a95f739e58503da7af3714bc7 (diff) | |
download | weechat-fae9bdf8f8cf51eb07602dc8f6633e380ff94b20.zip |
trigger: add variables "${tg_shell_argc}" and "${tg_shell_argvN}" in command trigger evaluated strings (closes #1624)
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/trigger/trigger-callback.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/plugins/trigger/trigger-callback.c b/src/plugins/trigger/trigger-callback.c index eeefb8aad..caefc06ca 100644 --- a/src/plugins/trigger/trigger-callback.c +++ b/src/plugins/trigger/trigger-callback.c @@ -1042,8 +1042,8 @@ trigger_callback_command_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { - char str_name[32], str_temp[128]; - int i; + char str_name[64], str_value[128], **shell_argv; + int i, shell_argc; TRIGGER_CALLBACK_CB_INIT(WEECHAT_RC_OK); @@ -1053,8 +1053,8 @@ trigger_callback_command_cb (const void *pointer, void *data, /* add data in hashtables used for conditions/replace/command */ trigger_callback_set_common_vars (trigger, extra_vars); weechat_hashtable_set (pointers, "buffer", buffer); - snprintf (str_temp, sizeof (str_temp), "%d", argc); - weechat_hashtable_set (extra_vars, "tg_argc", str_temp); + snprintf (str_value, sizeof (str_value), "%d", argc); + weechat_hashtable_set (extra_vars, "tg_argc", str_value); for (i = 0; i < argc; i++) { snprintf (str_name, sizeof (str_name), "tg_argv%d", i); @@ -1062,6 +1062,22 @@ trigger_callback_command_cb (const void *pointer, void *data, snprintf (str_name, sizeof (str_name), "tg_argv_eol%d", i); weechat_hashtable_set (extra_vars, str_name, argv_eol[i]); } + shell_argv = weechat_string_split_shell (argv_eol[0], &shell_argc); + if (shell_argv) + { + snprintf (str_value, sizeof (str_value), "%d", shell_argc); + weechat_hashtable_set (extra_vars, "tg_shell_argc", str_value); + for (i = 0; i < shell_argc; i++) + { + snprintf (str_name, sizeof (str_name), "tg_shell_argv%d", i); + weechat_hashtable_set (extra_vars, str_name, shell_argv[i]); + } + weechat_string_free_split (shell_argv); + } + else + { + weechat_hashtable_set (extra_vars, "tg_shell_argc", "0"); + } /* execute the trigger (conditions, regex, command) */ if (!trigger_callback_execute (trigger, buffer, pointers, extra_vars, NULL)) |