summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2012-08-21 21:42:34 +0200
committerSebastien Helleu <flashcode@flashtux.org>2012-08-21 21:42:34 +0200
commit09f80c20d689831eaf2cf5a06f2e567a76ed0a73 (patch)
treedb9a59af54f7678b9ebea55c770611d85a5d3b1c /src
parent129f32ce8ed0fb6d8b37ed945455144bd83ce95a (diff)
downloadweechat-09f80c20d689831eaf2cf5a06f2e567a76ed0a73.zip
script: add options -o and -i for /script list
Diffstat (limited to 'src')
-rw-r--r--src/plugins/script/script-action.c69
-rw-r--r--src/plugins/script/script-command.c9
2 files changed, 74 insertions, 4 deletions
diff --git a/src/plugins/script/script-action.c b/src/plugins/script/script-action.c
index e74e4ee8c..dcf9eff03 100644
--- a/src/plugins/script/script-action.c
+++ b/src/plugins/script/script-action.c
@@ -92,6 +92,63 @@ script_action_list ()
}
/*
+ * script_action_list_input: list loaded scripts (all languages) in input
+ * (send it to buffer if send_to_buffer == 1)
+ */
+
+void
+script_action_list_input (int send_to_buffer)
+{
+ int i, length;
+ char hdata_name[128], *buf, str_pos[16];
+ struct t_hdata *hdata;
+ void *ptr_script;
+
+ buf = malloc (16384);
+ if (!buf)
+ return;
+
+ buf[0] = '\0';
+ length = 0;
+
+ for (i = 0; script_language[i]; i++)
+ {
+ snprintf (hdata_name, sizeof (hdata_name),
+ "%s_script", script_language[i]);
+ hdata = weechat_hdata_get (hdata_name);
+ ptr_script = weechat_hdata_get_list (hdata, "scripts");
+ while (ptr_script)
+ {
+ if (buf[0])
+ strcat (buf, ", ");
+ strcat (buf, weechat_hdata_string (hdata, ptr_script, "name"));
+ strcat (buf, " ");
+ strcat (buf, weechat_hdata_string (hdata, ptr_script, "version"));
+ length = strlen (buf);
+ if (length > 16384 - 64)
+ {
+ strcat (buf, "...");
+ length += 3;
+ break;
+ }
+ ptr_script = weechat_hdata_move (hdata, ptr_script, 1);
+ }
+ }
+
+ if (buf[0])
+ {
+ if (send_to_buffer)
+ weechat_command (weechat_current_buffer (), buf);
+ else
+ {
+ weechat_buffer_set (weechat_current_buffer (), "input", buf);
+ snprintf (str_pos, sizeof (str_pos), "%d", length);
+ weechat_buffer_set (weechat_current_buffer (), "input_pos", str_pos);
+ }
+ }
+}
+
+/*
* script_action_load: load a script
*/
@@ -687,7 +744,17 @@ script_action_run ()
}
else if (weechat_strcasecmp (argv[0], "list") == 0)
{
- script_action_list ();
+ if (argc > 1)
+ {
+ if (weechat_strcasecmp (argv[1], "-i") == 0)
+ script_action_list_input (0);
+ else if (weechat_strcasecmp (argv[1], "-o") == 0)
+ script_action_list_input (1);
+ else
+ script_action_list ();
+ }
+ else
+ script_action_list ();
}
else if (weechat_strcasecmp (argv[0], "load") == 0)
{
diff --git a/src/plugins/script/script-command.c b/src/plugins/script/script-command.c
index 0eb034aef..b92e3039b 100644
--- a/src/plugins/script/script-command.c
+++ b/src/plugins/script/script-command.c
@@ -164,7 +164,7 @@ script_command_script (void *data, struct t_gui_buffer *buffer, int argc,
if (weechat_strcasecmp (argv[1], "list") == 0)
{
- script_action_schedule ("list", 1, 0);
+ script_action_schedule (argv_eol[1], 1, 0);
return WEECHAT_RC_OK;
}
@@ -275,11 +275,14 @@ script_command_init ()
{
weechat_hook_command ("script",
N_("WeeChat scripts manager"),
- N_("list || search <text> || show <script>"
+ N_("list [-o|-i] || search <text> || show <script>"
" || load|unload|reload <script> [<script>...]"
" || install|remove|installremove|hold [-q] <script> [<script>...]"
" || upgrade || update"),
N_(" list: list loaded scripts (all languages)\n"
+ " -o: send list of loaded scripts to buffer\n"
+ " -i: copy list of loaded scripts in "
+ "command line (for sending to buffer)\n"
" search: search scripts by tags or text and "
"display result on scripts buffer\n"
" show: show detailed info about a script\n"
@@ -337,7 +340,7 @@ script_command_init ()
" /script hold urlserver.py\n"
" /script reload urlserver\n"
" /script upgrade"),
- "list"
+ "list -o|-i"
" || search %(script_tags)"
" || show %(script_scripts)"
" || load %(script_files)|%*"