about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2021-09-29 15:26:17 +0200
committerMichael Vetter <jubalh@iodoru.org>2021-09-29 17:32:54 +0200
commit25820235fe3460966eade8ea13734e1e2d2f1ed6 (patch)
treefbc1a4672deb28310d9d777f6b9017a1b6a87752 /src/command
parent7486e22b77d2d5467af2b21d3e38ba66a5bddf69 (diff)
downloadprofani-tty-25820235fe3460966eade8ea13734e1e2d2f1ed6.tar.gz
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
Diffstat (limited to 'src/command')
-rw-r--r--src/command/cmd_defs.c2
-rw-r--r--src/command/cmd_funcs.c36
2 files changed, 37 insertions, 1 deletions
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 [<plugin>]",
               "/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 [<path>]", "Install a plugin, or all plugins found in a directory (recursive)." },
               { "uninstall [<plugin>]", "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.");