From 25820235fe3460966eade8ea13734e1e2d2f1ed6 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 29 Sep 2021 15:26:17 +0200 Subject: List globally available plugins Packagers can package https://github.com/profanity-im/profanity-plugins or another collection of plugins to `/usr/local/share/profanity/plugins` (python) and `/usr/local/lib64/profanity` (c). `/plugins` will list these globally available plugins now along with the ones thare are installed (`~/.local/share/profanity/plugins`) and loaded. Regards https://github.com/profanity-im/profanity/issues/945 --- src/command/cmd_defs.c | 2 +- src/command/cmd_funcs.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 898608af..37a2db89 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2155,7 +2155,7 @@ static struct cmd_t command_defs[] = { "/plugins reload []", "/plugins python_version") CMD_DESC( - "Manage plugins. Passing no arguments lists currently loaded plugins.") + "Manage plugins. Passing no arguments lists currently loaded plugins and global plugins which are available for local installation. Global directory for Python plugins is " GLOBAL_PYTHON_PLUGINS_PATH " and for C Plugins is " GLOBAL_C_PLUGINS_PATH ".") CMD_ARGS( { "install []", "Install a plugin, or all plugins found in a directory (recursive)." }, { "uninstall []", "Uninstall a plugin." }, diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 302de659..ab48c3fb 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -7172,6 +7172,42 @@ cmd_plugins_python_version(ProfWin* window, const char* const command, gchar** a gboolean cmd_plugins(ProfWin* window, const char* const command, gchar** args) { + GDir* global_pyp_dir = NULL; + GDir* global_cp_dir = NULL; + + if (access(GLOBAL_PYTHON_PLUGINS_PATH, R_OK) == 0) { + GError* error = NULL; + global_pyp_dir = g_dir_open(GLOBAL_PYTHON_PLUGINS_PATH, 0, &error); + if (error) { + log_warning("Error when trying to open global plugins path: %s", GLOBAL_PYTHON_PLUGINS_PATH); + g_error_free(error); + return TRUE; + } + } + if (access(GLOBAL_C_PLUGINS_PATH, R_OK) == 0) { + GError* error = NULL; + global_cp_dir = g_dir_open(GLOBAL_C_PLUGINS_PATH, 0, &error); + if (error) { + log_warning("Error when trying to open global plugins path: %s", GLOBAL_C_PLUGINS_PATH); + g_error_free(error); + return TRUE; + } + } + if (global_pyp_dir) { + const gchar *filename; + cons_show("The following Python plugins are available globally and can be installed:"); + while ((filename = g_dir_read_name(global_pyp_dir))) { + cons_show(" %s", filename); + } + } + if (global_cp_dir) { + const gchar *filename; + cons_show("The following C plugins are available globally and can be installed:"); + while ((filename = g_dir_read_name(global_cp_dir))) { + cons_show(" %s", filename); + } + } + GList* plugins = plugins_loaded_list(); if (plugins == NULL) { cons_show("No plugins installed."); -- cgit 1.4.1-2-gfad0