mirror of
https://github.com/weechat/weechat.git
synced 2026-07-02 07:46:38 +02:00
script: add option "search" for command /script (completion with script tags)
This commit is contained in:
@@ -102,6 +102,16 @@ script_command_script (void *data, struct t_gui_buffer *buffer, int argc,
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
if (weechat_strcasecmp (argv[1], "search") == 0)
|
||||
{
|
||||
if (repo_scripts)
|
||||
script_repo_filter_scripts ((argc > 2) ? argv_eol[2] : NULL);
|
||||
else
|
||||
script_repo_set_filter ((argc > 2) ? argv_eol[2] : NULL);
|
||||
script_action_schedule ("buffer", 1, 0);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
if (weechat_strcasecmp (argv[1], "list") == 0)
|
||||
{
|
||||
script_action_schedule ("list", 1, 0);
|
||||
@@ -214,11 +224,13 @@ script_command_init ()
|
||||
{
|
||||
weechat_hook_command ("script",
|
||||
N_("WeeChat scripts manager"),
|
||||
N_("list || show <script>"
|
||||
N_("list || search <text> || show <script>"
|
||||
" || load|unload|reload <script> [<script>...]"
|
||||
" || install|remove|hold <script> [<script>...]"
|
||||
" || upgrade || update"),
|
||||
N_(" list: list loaded scripts (all languages)\n"
|
||||
" search: search scripts by tags or text and "
|
||||
"display result on scripts buffer\n"
|
||||
" show: show detailed info about a script\n"
|
||||
" load: load script(s)\n"
|
||||
" unload: unload script(s)\n"
|
||||
@@ -259,12 +271,14 @@ script_command_init ()
|
||||
"scripts (description, tags, ...)\n"
|
||||
" * remove filter\n\n"
|
||||
"Examples:\n"
|
||||
" /script search url\n"
|
||||
" /script install iset.pl buffers.pl\n"
|
||||
" /script remove iset.pl\n"
|
||||
" /script hold urlserver.py\n"
|
||||
" /script reload urlserver\n"
|
||||
" /script upgrade"),
|
||||
"list"
|
||||
" || search %(script_tags)"
|
||||
" || show %(script_scripts)"
|
||||
" || load %(script_files)|%*"
|
||||
" || unload %(python_script)|%(perl_script)|"
|
||||
|
||||
@@ -173,6 +173,48 @@ script_completion_scripts_files_cb (void *data, const char *completion_item,
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* script_completion_tags_cb: callback for completion with tags from scripts in
|
||||
* repository
|
||||
*/
|
||||
|
||||
int
|
||||
script_completion_tags_cb (void *data, const char *completion_item,
|
||||
struct t_gui_buffer *buffer,
|
||||
struct t_gui_completion *completion)
|
||||
{
|
||||
struct t_repo_script *ptr_script;
|
||||
char **list_tags;
|
||||
int num_tags, i;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) completion_item;
|
||||
(void) buffer;
|
||||
|
||||
for (ptr_script = repo_scripts; ptr_script;
|
||||
ptr_script = ptr_script->next_script)
|
||||
{
|
||||
if (ptr_script->tags)
|
||||
{
|
||||
list_tags = weechat_string_split (ptr_script->tags, ",", 0, 0,
|
||||
&num_tags);
|
||||
if (list_tags)
|
||||
{
|
||||
for (i = 0; i < num_tags; i++)
|
||||
{
|
||||
weechat_hook_completion_list_add (completion,
|
||||
list_tags[i],
|
||||
0, WEECHAT_LIST_POS_SORT);
|
||||
}
|
||||
weechat_string_free_split (list_tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* script_completion_init: init completion for script plugin
|
||||
*/
|
||||
@@ -189,4 +231,7 @@ script_completion_init ()
|
||||
weechat_hook_completion ("script_files",
|
||||
N_("files in script directories"),
|
||||
&script_completion_scripts_files_cb, NULL);
|
||||
weechat_hook_completion ("script_tags",
|
||||
N_("tags of scripts in repository"),
|
||||
&script_completion_tags_cb, NULL);
|
||||
}
|
||||
|
||||
+110
-105
@@ -727,6 +727,115 @@ script_repo_update_status_all ()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* script_repo_set_filter: set filter for scripts
|
||||
*/
|
||||
|
||||
void
|
||||
script_repo_set_filter (const char *filter)
|
||||
{
|
||||
if (script_repo_filter)
|
||||
free (script_repo_filter);
|
||||
script_repo_filter = (filter) ? strdup (filter) : NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* script_repo_match_filter: return 1 if script is matching filter string,
|
||||
* otherwise 0
|
||||
*/
|
||||
|
||||
int
|
||||
script_repo_match_filter (struct t_repo_script *script)
|
||||
{
|
||||
char **words, **tags;
|
||||
int num_words, num_tags, has_tag, match, i, j;
|
||||
|
||||
if (!script_repo_filter || strcmp (script_repo_filter, "*") == 0)
|
||||
return 1;
|
||||
|
||||
words = weechat_string_split (script_repo_filter, " ", 0, 0, &num_words);
|
||||
tags = weechat_string_split ((script->tags) ? script->tags : "", ",", 0, 0,
|
||||
&num_tags);
|
||||
if (words)
|
||||
{
|
||||
for (i = 0; i < num_words; i++)
|
||||
{
|
||||
has_tag = 0;
|
||||
if (tags)
|
||||
{
|
||||
for (j = 0; j < num_tags; j++)
|
||||
{
|
||||
if (weechat_strcasecmp (tags[j], words[i]) == 0)
|
||||
{
|
||||
has_tag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!has_tag)
|
||||
{
|
||||
match = 0;
|
||||
if (script->name_with_extension
|
||||
&& weechat_strcasestr (script->name_with_extension, words[i]))
|
||||
match = 1;
|
||||
|
||||
if (!match && script->description
|
||||
&& weechat_strcasestr (script->description, words[i]))
|
||||
match = 1;
|
||||
|
||||
if (!match && script->license
|
||||
&& weechat_strcasestr (script->license, words[i]))
|
||||
match = 1;
|
||||
|
||||
if (!match && script->author
|
||||
&& weechat_strcasestr (script->author, words[i]))
|
||||
match = 1;
|
||||
|
||||
if (!match)
|
||||
{
|
||||
weechat_string_free_split (words);
|
||||
weechat_string_free_split (tags);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (words)
|
||||
weechat_string_free_split (words);
|
||||
if (tags)
|
||||
weechat_string_free_split (tags);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* script_repo_filter_scripts: filter scripts (search string in
|
||||
* name/description/tags) and mark scripts found as
|
||||
* "displayed" (0 in displayed for non-matching
|
||||
* scripts)
|
||||
*/
|
||||
|
||||
void
|
||||
script_repo_filter_scripts (const char *search)
|
||||
{
|
||||
struct t_repo_script *ptr_script;
|
||||
|
||||
script_repo_set_filter (search);
|
||||
|
||||
script_repo_count_displayed = 0;
|
||||
|
||||
for (ptr_script = repo_scripts; ptr_script;
|
||||
ptr_script = ptr_script->next_script)
|
||||
{
|
||||
ptr_script->displayed = (script_repo_match_filter (ptr_script));
|
||||
if (ptr_script->displayed)
|
||||
script_repo_count_displayed++;
|
||||
}
|
||||
|
||||
script_buffer_refresh (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* script_repo_file_exists: return 1 if repository file (plugins.xml.gz) exists
|
||||
* otherwise 0
|
||||
@@ -839,12 +948,6 @@ script_repo_file_read (int quiet)
|
||||
else
|
||||
weechat_hashtable_remove_all (script_repo_max_length_field);
|
||||
|
||||
if (script_repo_filter)
|
||||
{
|
||||
free (script_repo_filter);
|
||||
script_repo_filter = NULL;
|
||||
}
|
||||
|
||||
version = weechat_info_get ("version", NULL);
|
||||
version_number = weechat_util_version_number (version);
|
||||
|
||||
@@ -965,6 +1068,7 @@ script_repo_file_read (int quiet)
|
||||
script_extension[script->language]);
|
||||
}
|
||||
script_repo_update_status (script);
|
||||
script->displayed = (script_repo_match_filter (script));
|
||||
script_repo_add (script);
|
||||
script_ok = 1;
|
||||
}
|
||||
@@ -1202,105 +1306,6 @@ script_repo_file_update (int quiet)
|
||||
free (filename);
|
||||
}
|
||||
|
||||
/*
|
||||
* script_repo_match_search: return 1 if script is matching search string,
|
||||
* otherwise 0
|
||||
*/
|
||||
|
||||
int
|
||||
script_repo_match_search (struct t_repo_script *script, const char *search)
|
||||
{
|
||||
char **words, **tags;
|
||||
int num_words, num_tags, has_tag, match, i, j;
|
||||
|
||||
if (strcmp (search, "*") == 0)
|
||||
return 1;
|
||||
|
||||
words = weechat_string_split (search, " ", 0, 0, &num_words);
|
||||
tags = weechat_string_split ((script->tags) ? script->tags : "", ",", 0, 0,
|
||||
&num_tags);
|
||||
if (words)
|
||||
{
|
||||
for (i = 0; i < num_words; i++)
|
||||
{
|
||||
has_tag = 0;
|
||||
if (tags)
|
||||
{
|
||||
for (j = 0; j < num_tags; j++)
|
||||
{
|
||||
if (weechat_strcasecmp (tags[j], words[i]) == 0)
|
||||
{
|
||||
has_tag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!has_tag)
|
||||
{
|
||||
match = 0;
|
||||
if (script->name_with_extension
|
||||
&& weechat_strcasestr (script->name_with_extension, words[i]))
|
||||
match = 1;
|
||||
|
||||
if (!match && script->description
|
||||
&& weechat_strcasestr (script->description, words[i]))
|
||||
match = 1;
|
||||
|
||||
if (!match && script->license
|
||||
&& weechat_strcasestr (script->license, words[i]))
|
||||
match = 1;
|
||||
|
||||
if (!match && script->author
|
||||
&& weechat_strcasestr (script->author, words[i]))
|
||||
match = 1;
|
||||
|
||||
if (!match)
|
||||
{
|
||||
weechat_string_free_split (words);
|
||||
weechat_string_free_split (tags);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (words)
|
||||
weechat_string_free_split (words);
|
||||
if (tags)
|
||||
weechat_string_free_split (tags);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* script_repo_filter_scripts: filter scripts (search string in
|
||||
* name/description/tags) and mark scripts found as
|
||||
* "displayed" (0 in displayed for non-matching
|
||||
* scripts)
|
||||
*/
|
||||
|
||||
void
|
||||
script_repo_filter_scripts (const char *search)
|
||||
{
|
||||
struct t_repo_script *ptr_script;
|
||||
|
||||
if (script_repo_filter)
|
||||
free (script_repo_filter);
|
||||
script_repo_filter = strdup (search);
|
||||
|
||||
script_repo_count_displayed = 0;
|
||||
|
||||
for (ptr_script = repo_scripts; ptr_script;
|
||||
ptr_script = ptr_script->next_script)
|
||||
{
|
||||
ptr_script->displayed = (script_repo_match_search (ptr_script, search));
|
||||
if (ptr_script->displayed)
|
||||
script_repo_count_displayed++;
|
||||
}
|
||||
|
||||
script_buffer_refresh (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* script_repo_hdata_script_cb: return hdata for script
|
||||
*/
|
||||
|
||||
@@ -70,11 +70,12 @@ extern const char *script_repo_get_status_for_display (struct t_repo_script *scr
|
||||
extern void script_repo_remove_all ();
|
||||
extern void script_repo_update_status (struct t_repo_script *script);
|
||||
extern void script_repo_update_status_all ();
|
||||
extern void script_repo_set_filter (const char *filter);
|
||||
extern void script_repo_filter_scripts (const char *search);
|
||||
extern int script_repo_file_exists ();
|
||||
extern int script_repo_file_is_uptodate ();
|
||||
extern int script_repo_file_read (int quiet);
|
||||
extern void script_repo_file_update (int quiet);
|
||||
extern void script_repo_filter_scripts (const char *search);
|
||||
extern struct t_hdata *script_repo_hdata_script_cb (void *data,
|
||||
const char *hdata_name);
|
||||
extern int script_repo_add_to_infolist (struct t_infolist *infolist,
|
||||
|
||||
Reference in New Issue
Block a user