1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-16 21:35:24 +00:00

Implemented /script list

This commit is contained in:
James Booth 2015-10-17 22:30:01 +01:00
parent 0769fc6b1b
commit a35cbea732
7 changed files with 53 additions and 5 deletions

View File

@ -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");
}

View File

@ -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);
}

View File

@ -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

View File

@ -35,4 +35,5 @@
#include <glib.h>
void scripts_init(void);
GSList* scripts_list(void);
gboolean scripts_exec(const char *const script);

View File

@ -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)
{

View File

@ -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,

View File

@ -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)
{