Add /plugins install command

This commit is contained in:
James Booth
2016-07-12 23:50:21 +01:00
parent 5f393a6d9f
commit 0991699ae6
7 changed files with 218 additions and 106 deletions

View File

@@ -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;