summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2015-07-20 07:54:59 +0200
committerSébastien Helleu <flashcode@flashtux.org>2015-07-20 07:54:59 +0200
commitb1bd5c721e66fc4ff414516ad839622988b65e71 (patch)
tree7b16c3bf8346ebc0cf79a4b67f85c888e82f238d /src/plugins
parent31c3151fcc9d278b0ec06652620df5ca1a40ed62 (diff)
downloadweechat-b1bd5c721e66fc4ff414516ad839622988b65e71.zip
alias: add options "add", "addcompletion" and "del" in command /alias, remove command /unalias (closes #458)
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/alias/CMakeLists.txt2
-rw-r--r--src/plugins/alias/Makefile.am4
-rw-r--r--src/plugins/alias/alias-command.c266
-rw-r--r--src/plugins/alias/alias-command.h25
-rw-r--r--src/plugins/alias/alias-completion.c116
-rw-r--r--src/plugins/alias/alias-completion.h25
-rw-r--r--src/plugins/alias/alias.c317
7 files changed, 443 insertions, 312 deletions
diff --git a/src/plugins/alias/CMakeLists.txt b/src/plugins/alias/CMakeLists.txt
index 15808c291..7214efbc3 100644
--- a/src/plugins/alias/CMakeLists.txt
+++ b/src/plugins/alias/CMakeLists.txt
@@ -19,6 +19,8 @@
add_library(alias MODULE
alias.c alias.h
+alias-command.c alias-command.h
+alias-completion.c alias-completion.h
alias-config.c alias-config.h
alias-info.c alias-info.h)
set_target_properties(alias PROPERTIES PREFIX "")
diff --git a/src/plugins/alias/Makefile.am b/src/plugins/alias/Makefile.am
index b92a60d75..0214ef60d 100644
--- a/src/plugins/alias/Makefile.am
+++ b/src/plugins/alias/Makefile.am
@@ -25,6 +25,10 @@ lib_LTLIBRARIES = alias.la
alias_la_SOURCES = alias.c \
alias.h \
+ alias-command.c \
+ alias-command.h \
+ alias-completion.c \
+ alias-completion.h \
alias-config.c \
alias-config.h \
alias-info.c \
diff --git a/src/plugins/alias/alias-command.c b/src/plugins/alias/alias-command.c
new file mode 100644
index 000000000..74c1964ff
--- /dev/null
+++ b/src/plugins/alias/alias-command.c
@@ -0,0 +1,266 @@
+/*
+ * alias-command.c - alias commands
+ *
+ * Copyright (C) 2003-2015 Sébastien Helleu <flashcode@flashtux.org>
+ *
+ * This file is part of WeeChat, the extensible chat client.
+ *
+ * WeeChat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * WeeChat is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with WeeChat. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "../weechat-plugin.h"
+#include "alias.h"
+#include "alias-config.h"
+
+/*
+ * Adds a new alias.
+ */
+
+void
+alias_command_add (const char *alias_name, const char *command,
+ const char *completion)
+{
+ struct t_config_option *ptr_option;
+
+ /* define new alias */
+ if (!alias_new (alias_name, command, completion))
+ {
+ weechat_printf (NULL,
+ _("%s%s: error creating alias \"%s\" "
+ "=> \"%s\""),
+ weechat_prefix ("error"), ALIAS_PLUGIN_NAME,
+ alias_name, command);
+ return;
+ }
+
+ /* create configuration option for command */
+ ptr_option = weechat_config_search_option (alias_config_file,
+ alias_config_section_cmd,
+ alias_name);
+ if (ptr_option)
+ weechat_config_option_free (ptr_option);
+ alias_config_cmd_new_option (alias_name, command);
+
+ /* create configuration option for completion */
+ ptr_option = weechat_config_search_option (alias_config_file,
+ alias_config_section_completion,
+ alias_name);
+ if (ptr_option)
+ weechat_config_option_free (ptr_option);
+ if (completion)
+ alias_config_completion_new_option (alias_name, completion);
+
+ /* display message */
+ weechat_printf (NULL,
+ _("Alias \"%s\" => \"%s\" created"),
+ alias_name, command);
+}
+
+/*
+ * Callback for command "/alias": displays or creates alias.
+ */
+
+int
+alias_command_cb (void *data, struct t_gui_buffer *buffer, int argc,
+ char **argv, char **argv_eol)
+{
+ char *ptr_alias_name;
+ struct t_alias *ptr_alias;
+ struct t_config_option *ptr_option;
+ int alias_found, i;
+
+ /* make C compiler happy */
+ (void) data;
+ (void) buffer;
+
+ /* List all aliases */
+ if ((argc == 1) || (weechat_strcasecmp (argv[1], "list") == 0))
+ {
+ if (alias_list)
+ {
+ /* get pointer to alias name */
+ ptr_alias_name = NULL;
+ if (argc > 1)
+ {
+ ptr_alias_name = (weechat_string_is_command_char (argv[2])) ?
+ (char *)weechat_utf8_next_char (argv[2]) : argv[2];
+ }
+
+ /* display list of aliases */
+ alias_found = 0;
+ for (ptr_alias = alias_list; ptr_alias;
+ ptr_alias = ptr_alias->next_alias)
+ {
+ if (!ptr_alias_name
+ || weechat_strcasestr (ptr_alias->name, ptr_alias_name))
+ {
+ if (!alias_found)
+ {
+ weechat_printf (NULL, "");
+ if (ptr_alias_name)
+ {
+ weechat_printf (NULL,
+ _("Aliases with \"%s\":"),
+ ptr_alias_name);
+ }
+ else
+ {
+ weechat_printf (NULL, _("All aliases:"));
+ }
+ }
+ weechat_printf (NULL, " %s %s=>%s %s",
+ ptr_alias->name,
+ weechat_color ("chat_delimiters"),
+ weechat_color ("chat"),
+ ptr_alias->command);
+ alias_found = 1;
+ }
+ }
+ if (!alias_found)
+ {
+ weechat_printf (NULL, _("No alias found matching \"%s\""),
+ (ptr_alias_name) ? ptr_alias_name : "");
+ }
+ }
+ else
+ {
+ weechat_printf (NULL, _("No alias defined"));
+ }
+ return WEECHAT_RC_OK;
+ }
+
+ if (weechat_strcasecmp (argv[1], "add") == 0)
+ {
+ WEECHAT_COMMAND_MIN_ARGS(4, "add");
+ alias_command_add (
+ (weechat_string_is_command_char (argv[2])) ?
+ (char *)weechat_utf8_next_char (argv[2]) : argv[2],
+ argv_eol[3],
+ NULL);
+ return WEECHAT_RC_OK;
+ }
+
+ if (weechat_strcasecmp (argv[1], "addcompletion") == 0)
+ {
+ WEECHAT_COMMAND_MIN_ARGS(5, "add");
+ alias_command_add (
+ (weechat_string_is_command_char (argv[3])) ?
+ (char *)weechat_utf8_next_char (argv[3]) : argv[3],
+ argv_eol[4],
+ argv[2]);
+ return WEECHAT_RC_OK;
+ }
+
+ if (weechat_strcasecmp (argv[1], "del") == 0)
+ {
+ WEECHAT_COMMAND_MIN_ARGS(3, "del");
+ for (i = 2; i < argc; i++)
+ {
+ ptr_alias_name = (weechat_string_is_command_char (argv[i])) ?
+ (char *)weechat_utf8_next_char (argv[i]) : argv[i];
+ ptr_alias = alias_search (ptr_alias_name);
+ if (!ptr_alias)
+ {
+ weechat_printf (NULL,
+ _("%sAlias \"%s\" not found"),
+ weechat_prefix ("error"),
+ ptr_alias_name);
+ }
+ else
+ {
+ /* remove alias */
+ alias_free (ptr_alias);
+
+ /* remove options */
+ ptr_option = weechat_config_search_option (
+ alias_config_file,
+ alias_config_section_cmd,
+ ptr_alias_name);
+ if (ptr_option)
+ weechat_config_option_free (ptr_option);
+ ptr_option = weechat_config_search_option (
+ alias_config_file,
+ alias_config_section_completion,
+ ptr_alias_name);
+ if (ptr_option)
+ weechat_config_option_free (ptr_option);
+
+ weechat_printf (NULL,
+ _("Alias \"%s\" removed"),
+ ptr_alias_name);
+ }
+ }
+ return WEECHAT_RC_OK;
+ }
+
+ WEECHAT_COMMAND_ERROR;
+}
+
+/*
+ * Hooks alias command.
+ */
+
+void
+alias_command_init ()
+{
+ weechat_hook_command (
+ "alias",
+ N_("list, add or remove command aliases"),
+ N_("list [<alias>]"
+ " || add <alias> [<command>[;<command>...]]"
+ " || addcompletion <completion> <alias> [<command>[;<command>...]]"
+ " || del <alias> [<alias>...]"),
+ N_(" list: list aliases (without argument, this list is "
+ "displayed)\n"
+ " add: add an alias\n"
+ "addcompletion: add an alias with a custom completion\n"
+ " del: delete an alias\n"
+ " completion: completion for alias: by default completion is "
+ "done with target command\n"
+ " note: you can use %%command to use completion of "
+ "an existing command\n"
+ " alias: name of alias\n"
+ " command: command name with arguments (many commands can be "
+ "separated by semicolons)\n"
+ "\n"
+ "Note: in command, special variables are replaced:\n"
+ " $n: argument 'n' (between 1 and 9)\n"
+ " $-m: arguments from 1 to 'm'\n"
+ " $n-: arguments from 'n' to last\n"
+ " $n-m: arguments from 'n' to 'm'\n"
+ " $*: all arguments\n"
+ " $~: last argument\n"
+ " $var: where \"var\" is a local variable of buffer (see "
+ "/buffer localvar)\n"
+ " examples: $nick, $channel, $server, $plugin, $name\n"
+ "\n"
+ "Examples:\n"
+ " alias /split to split window horizontally:\n"
+ " /alias add split /window splith\n"
+ " alias /hello to say \"hello\" on all channels but not on "
+ "#weechat:\n"
+ " /alias add hello /allchan -exclude=#weechat msg * hello\n"
+ " alias /forcejoin to send IRC command \"forcejoin\" with "
+ "completion of /sajoin:\n"
+ " /alias addcompletion %%sajoin forcejoin /quote forcejoin"),
+ "list %(alias)"
+ " || add %(alias) %(commands)|%(alias_value)"
+ " || addcompletion %- %(alias) %(commands)|%(alias_value)"
+ " || del %(alias)|%*",
+ &alias_command_cb, NULL);
+}
diff --git a/src/plugins/alias/alias-command.h b/src/plugins/alias/alias-command.h
new file mode 100644
index 000000000..14b75dbef
--- /dev/null
+++ b/src/plugins/alias/alias-command.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2013-2015 Sébastien Helleu <flashcode@flashtux.org>
+ *
+ * This file is part of WeeChat, the extensible chat client.
+ *
+ * WeeChat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * WeeChat is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with WeeChat. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef WEECHAT_ALIAS_COMMAND_H
+#define WEECHAT_ALIAS_COMMAND_H 1
+
+extern void alias_command_init ();
+
+#endif /* WEECHAT_ALIAS_COMMAND_H */
diff --git a/src/plugins/alias/alias-completion.c b/src/plugins/alias/alias-completion.c
new file mode 100644
index 000000000..44a590abc
--- /dev/null
+++ b/src/plugins/alias/alias-completion.c
@@ -0,0 +1,116 @@
+/*
+ * alias-completion.c - completion for alias commands
+ *
+ * Copyright (C) 2003-2015 Sébastien Helleu <flashcode@flashtux.org>
+ *
+ * This file is part of WeeChat, the extensible chat client.
+ *
+ * WeeChat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * WeeChat is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with WeeChat. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "../weechat-plugin.h"
+#include "alias.h"
+
+
+/*
+ * Adds list of aliases to completion list.
+ */
+
+int
+alias_completion_alias_cb (void *data, const char *completion_item,
+ struct t_gui_buffer *buffer,
+ struct t_gui_completion *completion)
+{
+ struct t_alias *ptr_alias;
+
+ /* make C compiler happy */
+ (void) data;
+ (void) completion_item;
+ (void) buffer;
+
+ for (ptr_alias = alias_list; ptr_alias;
+ ptr_alias = ptr_alias->next_alias)
+ {
+ weechat_hook_completion_list_add (completion, ptr_alias->name,
+ 0, WEECHAT_LIST_POS_SORT);
+ }
+
+ return WEECHAT_RC_OK;
+}
+
+/*
+ * Adds value of an alias to completion list.
+ */
+
+int
+alias_completion_alias_value_cb (void *data, const char *completion_item,
+ struct t_gui_buffer *buffer,
+ struct t_gui_completion *completion)
+{
+ const char *args;
+ char **argv, *alias_name;
+ int argc;
+ struct t_alias *ptr_alias;
+
+ /* make C compiler happy */
+ (void) data;
+ (void) completion_item;
+ (void) buffer;
+
+ args = weechat_hook_completion_get_string (completion, "args");
+ if (args)
+ {
+ argv = weechat_string_split (args, " ", 0, 0, &argc);
+ if (argv)
+ {
+ if (argc > 0)
+ alias_name = strdup (argv[argc - 1]);
+ else
+ alias_name = strdup (args);
+
+ if (alias_name)
+ {
+ ptr_alias = alias_search (alias_name);
+ if (ptr_alias)
+ {
+ weechat_hook_completion_list_add (completion,
+ ptr_alias->command,
+ 0,
+ WEECHAT_LIST_POS_BEGINNING);
+ }
+ free (alias_name);
+ }
+ weechat_string_free_split (argv);
+ }
+ }
+
+ return WEECHAT_RC_OK;
+}
+
+/*
+ * Hooks completions.
+ */
+
+void
+alias_completion_init ()
+{
+ weechat_hook_completion ("alias", N_("list of aliases"),
+ &alias_completion_alias_cb, NULL);
+ weechat_hook_completion ("alias_value", N_("value of alias"),
+ &alias_completion_alias_value_cb, NULL);
+}
diff --git a/src/plugins/alias/alias-completion.h b/src/plugins/alias/alias-completion.h
new file mode 100644
index 000000000..eb5ca1e0d
--- /dev/null
+++ b/src/plugins/alias/alias-completion.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2013-2015 Sébastien Helleu <flashcode@flashtux.org>
+ *
+ * This file is part of WeeChat, the extensible chat client.
+ *
+ * WeeChat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * WeeChat is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with WeeChat. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef WEECHAT_ALIAS_COMPLETION_H
+#define WEECHAT_ALIAS_COMPLETION_H 1
+
+extern void alias_completion_init ();
+
+#endif /* WEECHAT_ALIAS_COMPLETION_H */
diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c
index b325e7120..48631604b 100644
--- a/src/plugins/alias/alias.c
+++ b/src/plugins/alias/alias.c
@@ -25,6 +25,8 @@
#include "../weechat-plugin.h"
#include "alias.h"
+#include "alias-command.h"
+#include "alias-completion.h"
#include "alias-config.h"
#include "alias-info.h"
@@ -639,268 +641,6 @@ alias_new (const char *name, const char *command, const char *completion)
}
/*
- * Callback for command "/alias": displays or creates alias.
- */
-
-int
-alias_command_cb (void *data, struct t_gui_buffer *buffer, int argc,
- char **argv, char **argv_eol)
-{
- char *ptr_completion, *ptr_alias_name, *ptr_command;
- struct t_alias *ptr_alias;
- struct t_config_option *ptr_option;
- int alias_found;
-
- /* make C compiler happy */
- (void) data;
- (void) buffer;
-
- /* List all aliases */
- if (argc == 1)
- {
- if (alias_list)
- {
- weechat_printf (NULL, "");
- weechat_printf (NULL, _("List of aliases:"));
- for (ptr_alias = alias_list; ptr_alias;
- ptr_alias = ptr_alias->next_alias)
- {
- weechat_printf (NULL,
- " %s %s=>%s %s",
- ptr_alias->name,
- weechat_color ("chat_delimiters"),
- weechat_color ("chat"),
- ptr_alias->command);
- }
- }
- else
- weechat_printf (NULL, _("No alias defined"));
- return WEECHAT_RC_OK;
- }
-
- if (argc > 2)
- {
- /* get pointers to completion, alias name and command (+ args) */
- ptr_completion = NULL;
- ptr_alias_name = NULL;
- ptr_command = NULL;
- if ((argc > 4) && (weechat_strcasecmp (argv[1], "-completion") == 0))
- {
- ptr_completion = argv[2];
- ptr_alias_name = (weechat_string_is_command_char (argv[3])) ?
- (char *)weechat_utf8_next_char (argv[3]) : argv[3];
- ptr_command = argv_eol[4];
- }
- else
- {
- ptr_alias_name = (weechat_string_is_command_char (argv[1])) ?
- (char *)weechat_utf8_next_char (argv[1]) : argv[1];
- ptr_command = argv_eol[2];
- }
-
- /* define new alias */
- if (!alias_new (ptr_alias_name, ptr_command, ptr_completion))
- {
- weechat_printf (NULL,
- _("%s%s: error creating alias \"%s\" "
- "=> \"%s\""),
- weechat_prefix ("error"), ALIAS_PLUGIN_NAME,
- ptr_alias_name, ptr_command);
- return WEECHAT_RC_OK;
- }
-
- /* create configuration option for command */
- ptr_option = weechat_config_search_option (alias_config_file,
- alias_config_section_cmd,
- ptr_alias_name);
- if (ptr_option)
- weechat_config_option_free (ptr_option);
- alias_config_cmd_new_option (ptr_alias_name, ptr_command);
-
- /* create configuration option for completion */
- ptr_option = weechat_config_search_option (alias_config_file,
- alias_config_section_completion,
- ptr_alias_name);
- if (ptr_option)
- weechat_config_option_free (ptr_option);
- if (ptr_completion)
- alias_config_completion_new_option (ptr_alias_name, ptr_completion);
-
- /* display message */
- weechat_printf (NULL,
- _("Alias \"%s\" => \"%s\" created"),
- ptr_alias_name, ptr_command);
- }
- else
- {
- /* get pointer to alias name */
- ptr_alias_name = (weechat_string_is_command_char (argv[1])) ?
- (char *)weechat_utf8_next_char (argv[1]) : argv[1];
-
- /* display list of aliases */
- alias_found = 0;
- for (ptr_alias = alias_list; ptr_alias;
- ptr_alias = ptr_alias->next_alias)
- {
- if (weechat_string_match (ptr_alias->name, ptr_alias_name, 0))
- {
- if (!alias_found)
- {
- weechat_printf (NULL, "");
- weechat_printf (NULL, _("List of aliases:"));
- }
- weechat_printf (NULL, " %s %s=>%s %s",
- ptr_alias->name,
- weechat_color ("chat_delimiters"),
- weechat_color ("chat"),
- ptr_alias->command);
- alias_found = 1;
- }
- }
- if (!alias_found)
- {
- weechat_printf (NULL, _("No alias found matching \"%s\""),
- ptr_alias_name);
- }
- }
-
- return WEECHAT_RC_OK;
-}
-
-/*
- * Callback for command "/unalias": removes an alias.
- */
-
-int
-unalias_command_cb (void *data, struct t_gui_buffer *buffer, int argc,
- char **argv, char **argv_eol)
-{
- int i;
- char *alias_name;
- struct t_alias *ptr_alias;
- struct t_config_option *ptr_option;
-
- /* make C compiler happy */
- (void) data;
- (void) buffer;
- (void) argv_eol;
-
- WEECHAT_COMMAND_MIN_ARGS(2, "");
-
- for (i = 1; i < argc; i++)
- {
- alias_name = (weechat_string_is_command_char (argv[i])) ?
- (char *)weechat_utf8_next_char (argv[i]) : argv[i];
- ptr_alias = alias_search (alias_name);
- if (!ptr_alias)
- {
- weechat_printf (NULL,
- _("%sAlias \"%s\" not found"),
- weechat_prefix ("error"),
- alias_name);
- }
- else
- {
- /* remove alias */
- alias_free (ptr_alias);
-
- /* remove options */
- ptr_option = weechat_config_search_option (alias_config_file,
- alias_config_section_cmd,
- alias_name);
- if (ptr_option)
- weechat_config_option_free (ptr_option);
- ptr_option = weechat_config_search_option (alias_config_file,
- alias_config_section_completion,
- alias_name);
- if (ptr_option)
- weechat_config_option_free (ptr_option);
-
- weechat_printf (NULL,
- _("Alias \"%s\" removed"),
- alias_name);
- }
- }
-
- return WEECHAT_RC_OK;
-}
-
-/*
- * Adds list of aliases to completion list.
- */
-
-int
-alias_completion_cb (void *data, const char *completion_item,
- struct t_gui_buffer *buffer,
- struct t_gui_completion *completion)
-{
- struct t_alias *ptr_alias;
-
- /* make C compiler happy */
- (void) data;
- (void) completion_item;
- (void) buffer;
-
- for (ptr_alias = alias_list; ptr_alias;
- ptr_alias = ptr_alias->next_alias)
- {
- weechat_hook_completion_list_add (completion, ptr_alias->name,
- 0, WEECHAT_LIST_POS_SORT);
- }
-
- return WEECHAT_RC_OK;
-}
-
-/*
- * Adds value of an alias to completion list.
- */
-
-int
-alias_value_completion_cb (void *data, const char *completion_item,
- struct t_gui_buffer *buffer,
- struct t_gui_completion *completion)
-{
- const char *args;
- char **argv, *alias_name;
- int argc;
- struct t_alias *ptr_alias;
-
- /* make C compiler happy */
- (void) data;
- (void) completion_item;
- (void) buffer;
-
- args = weechat_hook_completion_get_string (completion, "args");
- if (args)
- {
- argv = weechat_string_split (args, " ", 0, 0, &argc);
- if (argv)
- {
- if (argc > 0)
- alias_name = strdup (argv[argc - 1]);
- else
- alias_name = strdup (args);
-
- if (alias_name)
- {
- ptr_alias = alias_search (alias_name);
- if (ptr_alias)
- {
- weechat_hook_completion_list_add (completion,
- ptr_alias->command,
- 0,
- WEECHAT_LIST_POS_BEGINNING);
- }
- free (alias_name);
- }
- weechat_string_free_split (argv);
- }
- }
-
- return WEECHAT_RC_OK;
-}
-
-/*
* Adds an alias in an infolist.
*
* Returns:
@@ -952,56 +692,9 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
alias_config_read ();
- weechat_hook_command (
- "alias",
- N_("create an alias for a command"),
- N_("[-completion <completion>] <alias> [<command> [;<command>...]]"),
- N_("completion: completion for alias (optional, by default completion "
- "is done with target command)\n"
- " note: you can use %%command to use completion of an "
- "existing command\n"
- " alias: name of alias (wildcard \"*\" is allowed)\n"
- " command: command name with arguments (many commands can be "
- "separated by semicolons)\n"
- "\n"
- "Without argument, this command lists all defined alias.\n"
- "\n"
- "Note: in command, special variables are replaced:\n"
- " $n: argument 'n' (between 1 and 9)\n"
- " $-m: arguments from 1 to 'm'\n"
- " $n-: arguments from 'n' to last\n"
- " $n-m: arguments from 'n' to 'm'\n"
- " $*: all arguments\n"
- " $~: last argument\n"
- " $var: where \"var\" is a local variable of buffer (see "
- "/buffer localvar)\n"
- " examples: $nick, $channel, $server, $plugin, $name\n"
- "\n"
- "To remove an alias, use command /unalias.\n"
- "\n"
- "Examples:\n"
- " alias /split to split window horizontally:\n"
- " /alias split /window splith\n"
- " alias /hello to say \"hello\" on all channels but not on "
- "#weechat:\n"
- " /alias hello /allchan -exclude=#weechat msg * hello\n"
- " alias /forcejoin to send IRC command \"forcejoin\" with "
- "completion of /sajoin:\n"
- " /alias -completion %%sajoin forcejoin /quote forcejoin"),
- "-completion %- %(alias) %(commands)|%(alias_value)"
- " || %(alias) %(commands)|%(alias_value)",
- &alias_command_cb, NULL);
- weechat_hook_command (
- "unalias", N_("remove aliases"),
- N_("<alias> [<alias>...]"),
- N_("alias: name of alias to remove"),
- "%(alias)|%*",
- &unalias_command_cb, NULL);
-
- weechat_hook_completion ("alias", N_("list of aliases"),
- &alias_completion_cb, NULL);
- weechat_hook_completion ("alias_value", N_("value of alias"),
- &alias_value_completion_cb, NULL);
+ alias_command_init ();
+
+ alias_completion_init ();
alias_info_init ();