diff options
Diffstat (limited to 'src/config')
-rw-r--r-- | src/config/scripts.c | 26 | ||||
-rw-r--r-- | src/config/scripts.h | 1 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/config/scripts.c b/src/config/scripts.c index 17beb697..916e292c 100644 --- a/src/config/scripts.c +++ b/src/config/scripts.c @@ -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 diff --git a/src/config/scripts.h b/src/config/scripts.h index 114452af..9b56fac4 100644 --- a/src/config/scripts.h +++ b/src/config/scripts.h @@ -35,4 +35,5 @@ #include <glib.h> void scripts_init(void); +GSList* scripts_list(void); gboolean scripts_exec(const char *const script); |