summaryrefslogtreecommitdiff
path: root/src/core/wee-completion.c
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2014-01-14 13:27:43 +0100
committerSebastien Helleu <flashcode@flashtux.org>2014-01-14 13:27:43 +0100
commit70ffe0a14f286c9d258def51b2da7d1999bc9f83 (patch)
treeee65e8db1bd37b1e75229f4a64b139d49faab342 /src/core/wee-completion.c
parent5a292b28c0c5d41738b3bebcbf5f713a63f77952 (diff)
downloadweechat-70ffe0a14f286c9d258def51b2da7d1999bc9f83.zip
core: add completion "plugins_installed"
Diffstat (limited to 'src/core/wee-completion.c')
-rw-r--r--src/core/wee-completion.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/core/wee-completion.c b/src/core/wee-completion.c
index d394e633e..6e3066fee 100644
--- a/src/core/wee-completion.c
+++ b/src/core/wee-completion.c
@@ -41,6 +41,7 @@
#include "wee-proxy.h"
#include "wee-secure.h"
#include "wee-string.h"
+#include "wee-util.h"
#include "../gui/gui-completion.h"
#include "../gui/gui-bar.h"
#include "../gui/gui-bar-window.h"
@@ -731,6 +732,92 @@ completion_list_add_plugins_cb (void *data,
}
/*
+ * Adds a plugin installed to completion list.
+ */
+
+void
+completion_list_add_plugins_installed_exec_cb (void *data, const char *filename)
+{
+ struct t_gui_completion *completion;
+ const char *pos, *pos2;
+ char *name;
+
+ completion = (struct t_gui_completion *)data;
+
+ /* start after last '/' (or '\') in path */
+ pos = strrchr (filename, DIR_SEPARATOR_CHAR);
+ if (pos)
+ pos++;
+ else
+ pos = filename;
+
+ /* truncate after the last '.' in name */
+ pos2 = strrchr (pos, '.');
+ if (pos2)
+ name = string_strndup (pos, pos2 - pos);
+ else
+ name = strdup (pos);
+
+ if (name)
+ {
+ gui_completion_list_add (completion, name, 0, WEECHAT_LIST_POS_SORT);
+ free (name);
+ }
+}
+
+/*
+ * Adds plugins installed to completion list.
+ */
+
+int
+completion_list_add_plugins_installed_cb (void *data,
+ const char *completion_item,
+ struct t_gui_buffer *buffer,
+ struct t_gui_completion *completion)
+{
+ char *plugin_path, *plugin_path2, *dir_name;
+ int length;
+
+ /* make C compiler happy */
+ (void) data;
+ (void) completion_item;
+ (void) buffer;
+
+ /* plugins in WeeChat home dir */
+ if (CONFIG_STRING(config_plugin_path)
+ && CONFIG_STRING(config_plugin_path)[0])
+ {
+ plugin_path = string_expand_home (CONFIG_STRING(config_plugin_path));
+ plugin_path2 = string_replace ((plugin_path) ?
+ plugin_path : CONFIG_STRING(config_plugin_path),
+ "%h", weechat_home);
+ util_exec_on_files ((plugin_path2) ?
+ plugin_path2 : ((plugin_path) ?
+ plugin_path : CONFIG_STRING(config_plugin_path)),
+ 0,
+ completion,
+ &completion_list_add_plugins_installed_exec_cb);
+ if (plugin_path)
+ free (plugin_path);
+ if (plugin_path2)
+ free (plugin_path2);
+ }
+
+ /* plugins in WeeChat global lib dir */
+ length = strlen (WEECHAT_LIBDIR) + 16 + 1;
+ dir_name = malloc (length);
+ if (dir_name)
+ {
+ snprintf (dir_name, length, "%s/plugins", WEECHAT_LIBDIR);
+ util_exec_on_files (dir_name, 0, completion,
+ &completion_list_add_plugins_installed_exec_cb);
+ free (dir_name);
+ }
+
+ return WEECHAT_RC_OK;
+}
+
+/*
* Adds plugin commands to completion list.
*
* The plugin name is read in previous argument.
@@ -1416,6 +1503,9 @@ completion_init ()
hook_completion (NULL, "plugins_names", /* formerly "%p" */
N_("names of plugins"),
&completion_list_add_plugins_cb, NULL);
+ hook_completion (NULL, "plugins_installed",
+ N_("names of plugins installed"),
+ &completion_list_add_plugins_installed_cb, NULL);
hook_completion (NULL, "plugins_commands", /* formerly "%P" */
N_("commands defined by plugins"),
&completion_list_add_plugins_commands_cb, NULL);