diff options
author | James Booth <boothj5@gmail.com> | 2015-10-17 22:30:01 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-10-17 22:30:01 +0100 |
commit | a35cbea73273fb7e61218155ca1c28ebab73bb5b (patch) | |
tree | 8ac946f4912200120f5b4a0e9f46bb878b60f154 | |
parent | 0769fc6b1b0ec22d4e45f6cc033a642e25923930 (diff) | |
download | profani-tty-a35cbea73273fb7e61218155ca1c28ebab73bb5b.tar.gz |
Implemented /script list
-rw-r--r-- | src/command/command.c | 7 | ||||
-rw-r--r-- | src/command/commands.c | 4 | ||||
-rw-r--r-- | src/config/scripts.c | 26 | ||||
-rw-r--r-- | src/config/scripts.h | 1 | ||||
-rw-r--r-- | src/ui/console.c | 18 | ||||
-rw-r--r-- | src/ui/ui.h | 1 | ||||
-rw-r--r-- | tests/unittests/ui/stub_ui.c | 1 |
7 files changed, 53 insertions, 5 deletions
diff --git a/src/command/command.c b/src/command/command.c index 8b43ad21..35c2e32a 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -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"); } diff --git a/src/command/commands.c b/src/command/commands.c index cbc37046..58f2a9b2 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -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); } 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); diff --git a/src/ui/console.c b/src/ui/console.c index 6590cb78..2388e79b 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1582,6 +1582,24 @@ cons_show_themes(GSList *themes) } 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) { cons_show(""); diff --git a/src/ui/ui.h b/src/ui/ui.h index add38fb4..1a534012 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -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, diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index a4d95bd1..ae959740 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -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) { |