mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Implemented /script list
This commit is contained in:
parent
0769fc6b1b
commit
a35cbea732
@ -1693,19 +1693,17 @@ static struct cmd_t command_defs[] =
|
||||
},
|
||||
|
||||
{ "/script",
|
||||
cmd_script, parse_args, 2, 2, NULL,
|
||||
cmd_script, parse_args, 1, 2, NULL,
|
||||
CMD_NOTAGS
|
||||
CMD_SYN(
|
||||
"/script run <script>",
|
||||
"/script remove <script>",
|
||||
"/script list",
|
||||
"/script show <script>")
|
||||
CMD_DESC(
|
||||
"Manage and run command scripts. "
|
||||
"Run command scripts. "
|
||||
"Scripts are stored in $XDG_DATA_HOME/profanity/scripts/ which is usually $HOME/.local/share/profanity/scripts/.")
|
||||
CMD_ARGS(
|
||||
{ "script run <script>", "Execute a script." },
|
||||
{ "script remove <script>", "Remove a script TODO." },
|
||||
{ "script list", "List all scripts TODO." },
|
||||
{ "script show <script>", "Show the commands in script TODO." })
|
||||
CMD_EXAMPLES(
|
||||
@ -2202,7 +2200,6 @@ cmd_init(void)
|
||||
script_ac = autocomplete_new();
|
||||
autocomplete_add(script_ac, "run");
|
||||
autocomplete_add(script_ac, "list");
|
||||
autocomplete_add(script_ac, "remove");
|
||||
autocomplete_add(script_ac, "show");
|
||||
}
|
||||
|
||||
|
@ -698,6 +698,10 @@ cmd_script(ProfWin *window, const char * const command, gchar **args)
|
||||
if (!res) {
|
||||
cons_show("Could not find script %s", args[1]);
|
||||
}
|
||||
} else if (g_strcmp0(args[0], "list") == 0) {
|
||||
GSList *scripts = scripts_list();
|
||||
cons_show_scripts(scripts);
|
||||
g_slist_free_full(scripts, g_free);
|
||||
} else {
|
||||
cons_bad_cmd_usage(command);
|
||||
}
|
||||
|
@ -66,6 +66,32 @@ scripts_init(void)
|
||||
log_error("Error creating directory: %s", scriptsdir->str);
|
||||
}
|
||||
}
|
||||
|
||||
g_string_free(scriptsdir, TRUE);
|
||||
}
|
||||
|
||||
GSList*
|
||||
scripts_list(void)
|
||||
{
|
||||
gchar *data_home = xdg_get_data_home();
|
||||
GString *scriptsdir = g_string_new(data_home);
|
||||
free(data_home);
|
||||
g_string_append(scriptsdir, "/profanity/scripts");
|
||||
|
||||
GSList *result = NULL;
|
||||
GDir *scripts = g_dir_open(scriptsdir->str, 0, NULL);
|
||||
g_string_free(scriptsdir, TRUE);
|
||||
|
||||
if (scripts) {
|
||||
const gchar *script = g_dir_read_name(scripts);
|
||||
while (script) {
|
||||
result = g_slist_append(result, strdup(script));
|
||||
script = g_dir_read_name(scripts);
|
||||
}
|
||||
g_dir_close(scripts);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
@ -35,4 +35,5 @@
|
||||
#include <glib.h>
|
||||
|
||||
void scripts_init(void);
|
||||
GSList* scripts_list(void);
|
||||
gboolean scripts_exec(const char *const script);
|
||||
|
@ -1581,6 +1581,24 @@ cons_show_themes(GSList *themes)
|
||||
cons_alert();
|
||||
}
|
||||
|
||||
void
|
||||
cons_show_scripts(GSList *scripts)
|
||||
{
|
||||
cons_show("");
|
||||
|
||||
if (scripts == NULL) {
|
||||
cons_show("No scripts available.");
|
||||
} else {
|
||||
cons_show("Scripts:");
|
||||
while (scripts) {
|
||||
cons_show(scripts->data);
|
||||
scripts = g_slist_next(scripts);
|
||||
}
|
||||
}
|
||||
|
||||
cons_alert();
|
||||
}
|
||||
|
||||
void
|
||||
cons_prefs(void)
|
||||
{
|
||||
|
@ -278,6 +278,7 @@ void cons_show_status(const char * const barejid);
|
||||
void cons_show_info(PContact pcontact);
|
||||
void cons_show_caps(const char * const fulljid, resource_presence_t presence);
|
||||
void cons_show_themes(GSList *themes);
|
||||
void cons_show_scripts(GSList *scripts);
|
||||
void cons_show_aliases(GList *aliases);
|
||||
void cons_show_login_success(ProfAccount *account, int secured);
|
||||
void cons_show_software_version(const char * const jid,
|
||||
|
@ -415,6 +415,7 @@ void cons_show_status(const char * const barejid) {}
|
||||
void cons_show_info(PContact pcontact) {}
|
||||
void cons_show_caps(const char * const fulljid, resource_presence_t presence) {}
|
||||
void cons_show_themes(GSList *themes) {}
|
||||
void cons_show_scripts(GSList *scripts) {}
|
||||
|
||||
void cons_show_aliases(GList *aliases)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user