diff options
-rw-r--r-- | ChangeLog.adoc | 1 | ||||
-rw-r--r-- | doc/de/weechat_user.de.adoc | 14 | ||||
-rw-r--r-- | doc/en/weechat_user.en.adoc | 12 | ||||
-rw-r--r-- | doc/fr/weechat_user.fr.adoc | 12 | ||||
-rw-r--r-- | doc/it/weechat_user.it.adoc | 14 | ||||
-rw-r--r-- | doc/ja/weechat_user.ja.adoc | 14 | ||||
-rw-r--r-- | doc/pl/weechat_user.pl.adoc | 14 | ||||
-rw-r--r-- | src/plugins/trigger/trigger-callback.c | 24 |
8 files changed, 71 insertions, 34 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 3c1b85850..c74de34a6 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -24,6 +24,7 @@ New features:: * core: quit WeeChat by default when signal SIGHUP is received in normal run, reload configuration in weechat-headless (issue #1595) * api: add support of pointer names in function string_eval_expression (direct and in hdata) * api: add info "weechat_daemon" + * trigger: add variables "${tg_shell_argc}" and "${tg_shell_argvN}" in command trigger evaluated strings (issue #1624) Bug fixes:: diff --git a/doc/de/weechat_user.de.adoc b/doc/de/weechat_user.de.adoc index bc88185d1..857d665df 100644 --- a/doc/de/weechat_user.de.adoc +++ b/doc/de/weechat_user.de.adoc @@ -4543,11 +4543,15 @@ Der Callback von "command" legt folgende Variablen in der Hashtable an: [width="100%",cols="3m,2,14",options="header"] |=== -| Variable | Typ | Beschreibung -| buffer | pointer | Buffer. -| tg_argc | string | Die Anzahl von Argumenten (der Befehl wird mitgezählt). -| tg_argvN | string | Argument #N (`+tg_argv0+` ist der Befehl selber, die weiteren sind Argumente). -| tg_argv_eolN | string | von Argument #N bis zum Ende der Argumente (`+tg_argv_eol0+` enthält den eigentlichen Befehl). +| Variable | Typ | Beschreibung +| buffer | pointer | Buffer. +| tg_argc | string | Die Anzahl von Argumenten (der Befehl wird mitgezählt). +| tg_argvN | string | Argument #N (`+tg_argv0+` ist der Befehl selber, die weiteren sind Argumente). +| tg_argv_eolN | string | von Argument #N bis zum Ende der Argumente (`+tg_argv_eol0+` enthält den eigentlichen Befehl). +// TRANSLATION MISSING +| tg_shell_argc | string | The number of arguments with a split like the shell does (the command itself counts for one). +// TRANSLATION MISSING +| tg_shell_argvN | string | Argument #N with a split like the shell does (`+tg_shell_argv0+` is the command itself, the others are command arguments). |=== [[trigger_data_command_run]] diff --git a/doc/en/weechat_user.en.adoc b/doc/en/weechat_user.en.adoc index 04f2d61fe..40b767672 100644 --- a/doc/en/weechat_user.en.adoc +++ b/doc/en/weechat_user.en.adoc @@ -4453,11 +4453,13 @@ The "command" callback sets following variables in hashtable: [width="100%",cols="3m,2,14",options="header"] |=== -| Variable | Type | Description -| buffer | pointer | Buffer. -| tg_argc | string | The number of arguments (the command itself counts for one). -| tg_argvN | string | Argument #N (`+tg_argv0+` is the command itself, the others are command arguments). -| tg_argv_eolN | string | From argument #N until end of arguments (`+tg_argv_eol0+` includes the command itself). +| Variable | Type | Description +| buffer | pointer | Buffer. +| tg_argc | string | The number of arguments (the command itself counts for one). +| tg_argvN | string | Argument #N (`+tg_argv0+` is the command itself, the others are command arguments). +| tg_argv_eolN | string | From argument #N until end of arguments (`+tg_argv_eol0+` includes the command itself). +| tg_shell_argc | string | The number of arguments with a split like the shell does (the command itself counts for one). +| tg_shell_argvN | string | Argument #N with a split like the shell does (`+tg_shell_argv0+` is the command itself, the others are command arguments). |=== [[trigger_data_command_run]] diff --git a/doc/fr/weechat_user.fr.adoc b/doc/fr/weechat_user.fr.adoc index 789d81304..ed7af7922 100644 --- a/doc/fr/weechat_user.fr.adoc +++ b/doc/fr/weechat_user.fr.adoc @@ -4605,11 +4605,13 @@ de hachage : [width="100%",cols="3m,2,14",options="header"] |=== -| Variable | Type | Description -| buffer | pointeur | Tampon. -| tg_argc | chaîne | Nombre de paramètres (la commande elle-même compte pour un). -| tg_argvN | chaîne | Paramètre n°N (`+tg_argv0+` est la commande elle-même, les autres sont les paramètres de la commande). -| tg_argv_eolN | chaîne | Depuis le paramètre n°N jusqu'à la fin des paramètres (`+tg_argv_eol0+` inclut la commande elle-même). +| Variable | Type | Description +| buffer | pointeur | Tampon. +| tg_argc | chaîne | Nombre de paramètres (la commande elle-même compte pour un). +| tg_argvN | chaîne | Paramètre n°N (`+tg_argv0+` est la commande elle-même, les autres sont les paramètres de la commande). +| tg_argv_eolN | chaîne | Depuis le paramètre n°N jusqu'à la fin des paramètres (`+tg_argv_eol0+` inclut la commande elle-même). +| tg_shell_argc | chaîne | Nombre de paramètres avec un découpage comme le fait le shell (la commande elle-même compte pour un). +| tg_shell_argvN | chaîne | Paramètre n°N avec un découpage comme le fait le shell (`+tg_shell_argv0+` est la commande elle-même, les autres sont les paramètres de la commande). |=== [[trigger_data_command_run]] diff --git a/doc/it/weechat_user.it.adoc b/doc/it/weechat_user.it.adoc index de2a55a55..001e8af67 100644 --- a/doc/it/weechat_user.it.adoc +++ b/doc/it/weechat_user.it.adoc @@ -4773,11 +4773,15 @@ The "command" callback sets following variables in hashtable: [width="100%",cols="3m,2,14",options="header"] |=== -| Variable | Type | Description -| buffer | pointer | Buffer. -| tg_argc | string | The number of arguments (the command itself counts for one). -| tg_argvN | string | Argument #N (`+tg_argv0+` is the command itself, the others are command arguments). -| tg_argv_eolN | string | From argument #N until end of arguments (`+tg_argv_eol0+` includes the command itself). +| Variable | Type | Description +| buffer | pointer | Buffer. +| tg_argc | string | The number of arguments (the command itself counts for one). +| tg_argvN | string | Argument #N (`+tg_argv0+` is the command itself, the others are command arguments). +| tg_argv_eolN | string | From argument #N until end of arguments (`+tg_argv_eol0+` includes the command itself). +// TRANSLATION MISSING +| tg_shell_argc | string | The number of arguments with a split like the shell does (the command itself counts for one). +// TRANSLATION MISSING +| tg_shell_argvN | string | Argument #N with a split like the shell does (`+tg_shell_argv0+` is the command itself, the others are command arguments). |=== [[trigger_data_command_run]] diff --git a/doc/ja/weechat_user.ja.adoc b/doc/ja/weechat_user.ja.adoc index da45f5a5c..6cbd19330 100644 --- a/doc/ja/weechat_user.ja.adoc +++ b/doc/ja/weechat_user.ja.adoc @@ -4521,14 +4521,18 @@ _weechat_print_ 修飾子では、メッセージタグを使う変数 (下の [width="100%",cols="3m,2,14",options="header"] |=== -| 変数 | 型 | 説明 -| buffer | pointer | バッファ +| 変数 | 型 | 説明 +| buffer | pointer | バッファ // TRANSLATION MISSING -| tg_argc | string | The number of arguments (the command itself counts for one). +| tg_argc | string | The number of arguments (the command itself counts for one). // TRANSLATION MISSING -| tg_argvN | string | N 番目の引数 (`+tg_argv0+` is the command itself, the others are command arguments). +| tg_argvN | string | N 番目の引数 (`+tg_argv0+` is the command itself, the others are command arguments). // TRANSLATION MISSING -| tg_argv_eolN | string | N 番目の引数から最後の引数まで (`+tg_argv_eol0+` includes the command itself). +| tg_argv_eolN | string | N 番目の引数から最後の引数まで (`+tg_argv_eol0+` includes the command itself). +// TRANSLATION MISSING +| tg_shell_argc | string | The number of arguments with a split like the shell does (the command itself counts for one). +// TRANSLATION MISSING +| tg_shell_argvN | string | Argument #N with a split like the shell does (`+tg_shell_argv0+` is the command itself, the others are command arguments). |=== [[trigger_data_command_run]] diff --git a/doc/pl/weechat_user.pl.adoc b/doc/pl/weechat_user.pl.adoc index 1db0cd4ee..76bfc4bf0 100644 --- a/doc/pl/weechat_user.pl.adoc +++ b/doc/pl/weechat_user.pl.adoc @@ -4483,11 +4483,15 @@ Callback "command" ustawia następujące zmienne w tablicy hashy: [width="100%",cols="3m,2,14",options="header"] |=== -| Zmienna | Typ | Opis -| buffer | wskaźnik | Bufor. -| tg_argc | ciąg | Ilość argumentów (komenda liczy się za jeden). -| tg_argvN | ciąg | Argument #N (`+tg_argv0+` to komenda, pozostałe to jej argumenty). -| tg_argv_eolN | ciąg | Od argumentu #N do końca argumentów (`+tg_argv_eol0+` zawiera komendę). +| Zmienna | Typ | Opis +| buffer | wskaźnik | Bufor. +| tg_argc | ciąg | Ilość argumentów (komenda liczy się za jeden). +| tg_argvN | ciąg | Argument #N (`+tg_argv0+` to komenda, pozostałe to jej argumenty). +| tg_argv_eolN | ciąg | Od argumentu #N do końca argumentów (`+tg_argv_eol0+` zawiera komendę). +// TRANSLATION MISSING +| tg_shell_argc | ciąg | The number of arguments with a split like the shell does (the command itself counts for one). +// TRANSLATION MISSING +| tg_shell_argvN | ciąg | Argument #N with a split like the shell does (`+tg_shell_argv0+` is the command itself, the others are command arguments). |=== [[trigger_data_command_run]] 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)) |