about summary refs log tree commit diff stats
path: root/src/command/cmd_funcs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/command/cmd_funcs.c')
-rw-r--r--src/command/cmd_funcs.c45
1 files changed, 44 insertions, 1 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index fcce7028..05de90a5 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -6025,7 +6025,50 @@ cmd_xa(ProfWin *window, const char *const command, gchar **args)
 gboolean
 cmd_plugins(ProfWin *window, const char *const command, gchar **args)
 {
-    if (g_strcmp0(args[0], "load") == 0) {
+    if (g_strcmp0(args[0], "install") == 0) {
+        char *filename = args[1];
+        if (filename == NULL) {
+            cons_bad_cmd_usage(command);
+            return TRUE;
+        }
+
+        // expand ~ to $HOME
+        if (filename[0] == '~' && filename[1] == '/') {
+            if (asprintf(&filename, "%s/%s", getenv("HOME"), filename+2) == -1) {
+                return TRUE;
+            }
+        } else {
+            filename = strdup(filename);
+        }
+
+        if (access(filename, R_OK) != 0) {
+            cons_show("File not found: %s", filename);
+            free(filename);
+            return TRUE;
+        }
+
+        if (!is_regular_file(filename)) {
+            cons_show("Not a file: %s", filename);
+            free(filename);
+            return TRUE;
+        }
+
+        if (!g_str_has_suffix(filename, ".py") && !g_str_has_suffix(filename, ".so")) {
+            cons_show("Plugins must have one of the following extensions: '.py' '.so'");
+            free(filename);
+            return TRUE;
+        }
+
+        char *plugin_name = basename(filename);
+        gboolean result = plugins_install(plugin_name, filename);
+        if (result) {
+            cons_show("Plugin installed, use '/plugin load %s' to enable the plugin.", plugin_name);
+        } else {
+            cons_show("Failed to install plugin: %s", plugin_name);
+        }
+
+        return TRUE;
+    } else if (g_strcmp0(args[0], "load") == 0) {
         if (args[1] == NULL) {
             cons_bad_cmd_usage(command);
             return TRUE;