diff options
author | James Booth <boothj5@gmail.com> | 2015-10-15 23:57:52 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-10-15 23:57:52 +0100 |
commit | 0769fc6b1b0ec22d4e45f6cc033a642e25923930 (patch) | |
tree | d3c1daf4aabe110fcc6fd8489089e039e35d92ce | |
parent | ea4fb2ce6c1aa4f602447b8600ddce176df24c37 (diff) | |
download | profani-tty-0769fc6b1b0ec22d4e45f6cc033a642e25923930.tar.gz |
Added /script run
-rw-r--r-- | src/command/command.c | 35 | ||||
-rw-r--r-- | src/command/commands.c | 16 | ||||
-rw-r--r-- | src/command/commands.h | 1 |
3 files changed, 50 insertions, 2 deletions
diff --git a/src/command/command.c b/src/command/command.c index cd3a8c03..8b43ad21 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1691,6 +1691,28 @@ static struct cmd_t command_defs[] = "/xa", "/xa This meeting is going to be a long one") }, + + { "/script", + cmd_script, parse_args, 2, 2, NULL, + CMD_NOTAGS + CMD_SYN( + "/script run <script>", + "/script remove <script>", + "/script list", + "/script show <script>") + CMD_DESC( + "Manage and 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( + "/script list", + "/script run myscript", + "/script show somescript") + }, }; static Autocomplete commands_ac; @@ -1755,6 +1777,7 @@ static Autocomplete pgp_ac; static Autocomplete pgp_log_ac; static Autocomplete tls_ac; static Autocomplete tls_certpath_ac; +static Autocomplete script_ac; /* * Initialise command autocompleter and history @@ -2175,6 +2198,12 @@ cmd_init(void) tls_certpath_ac = autocomplete_new(); autocomplete_add(tls_certpath_ac, "set"); autocomplete_add(tls_certpath_ac, "clear"); + + script_ac = autocomplete_new(); + autocomplete_add(script_ac, "run"); + autocomplete_add(script_ac, "list"); + autocomplete_add(script_ac, "remove"); + autocomplete_add(script_ac, "show"); } void @@ -2242,6 +2271,7 @@ cmd_uninit(void) autocomplete_free(pgp_log_ac); autocomplete_free(tls_ac); autocomplete_free(tls_certpath_ac); + autocomplete_free(script_ac); } gboolean @@ -2426,6 +2456,7 @@ cmd_reset_autocomplete(ProfWin *window) autocomplete_reset(pgp_log_ac); autocomplete_reset(tls_ac); autocomplete_reset(tls_certpath_ac); + autocomplete_reset(script_ac); if (window->type == WIN_CHAT) { ProfChatWin *chatwin = (ProfChatWin*)window; @@ -2638,8 +2669,8 @@ _cmd_complete_parameters(ProfWin *window, const char * const input) } } - gchar *cmds[] = { "/prefs", "/disco", "/close", "/subject", "/room" }; - Autocomplete completers[] = { prefs_ac, disco_ac, close_ac, subject_ac, room_ac }; + gchar *cmds[] = { "/prefs", "/disco", "/close", "/subject", "/room", "/script" }; + Autocomplete completers[] = { prefs_ac, disco_ac, close_ac, subject_ac, room_ac, script_ac }; for (i = 0; i < ARRAY_SIZE(cmds); i++) { result = autocomplete_param_with_ac(input, cmds[i], completers[i], TRUE); diff --git a/src/command/commands.c b/src/command/commands.c index a58b8397..cbc37046 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -49,6 +49,7 @@ #include "config/preferences.h" #include "config/theme.h" #include "config/tlscerts.h" +#include "config/scripts.h" #include "contact.h" #include "roster_list.h" #include "jid.h" @@ -690,6 +691,21 @@ cmd_account(ProfWin *window, const char * const command, gchar **args) } gboolean +cmd_script(ProfWin *window, const char * const command, gchar **args) +{ + if ((g_strcmp0(args[0], "run") == 0) && args[1]) { + gboolean res = scripts_exec(args[1]); + if (!res) { + cons_show("Could not find script %s", args[1]); + } + } else { + cons_bad_cmd_usage(command); + } + + return TRUE; +} + +gboolean cmd_sub(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); diff --git a/src/command/commands.h b/src/command/commands.h index b3f83a70..d75559c5 100644 --- a/src/command/commands.h +++ b/src/command/commands.h @@ -149,6 +149,7 @@ gboolean cmd_time(ProfWin *window, const char * const command, gchar **args); gboolean cmd_resource(ProfWin *window, const char * const command, gchar **args); gboolean cmd_inpblock(ProfWin *window, const char * const command, gchar **args); gboolean cmd_encwarn(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_script(ProfWin *window, const char * const command, gchar **args); gboolean cmd_form_field(ProfWin *window, char *tag, gchar **args); |