]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/plugin.go
Add cd and pwd commands to change the working dir
[micro.git] / cmd / micro / plugin.go
index 607eb2b69eb9ca32912e0dc867a749370369faf3..d77baea9ba5fdf4e3c6eaecc757bfe553323aa4b 100644 (file)
@@ -12,12 +12,6 @@ import (
 
 var loadedPlugins []string
 
-var preInstalledPlugins = []string{
-       "go",
-       "linter",
-       "autoclose",
-}
-
 // Call calls the lua function 'function'
 // If it does not exist nothing happens, if there is an error,
 // the error is returned
@@ -120,47 +114,28 @@ func LuaFunctionJob(function string) func(string, ...string) {
 
 // LoadPlugins loads the pre-installed plugins and the plugins located in ~/.config/micro/plugins
 func LoadPlugins() {
-       files, _ := ioutil.ReadDir(configDir + "/plugins")
-       for _, plugin := range files {
-               if plugin.IsDir() {
-                       pluginName := plugin.Name()
-                       files, _ := ioutil.ReadDir(configDir + "/plugins/" + pluginName)
-                       for _, f := range files {
-                               if f.Name() == pluginName+".lua" {
-                                       data, _ := ioutil.ReadFile(configDir + "/plugins/" + pluginName + "/" + f.Name())
-                                       pluginDef := "\nlocal P = {}\n" + pluginName + " = P\nsetmetatable(" + pluginName + ", {__index = _G})\nsetfenv(1, P)\n"
-
-                                       if err := L.DoString(pluginDef + string(data)); err != nil {
-                                               TermMessage(err)
-                                               continue
-                                       }
-                                       loadedPlugins = append(loadedPlugins, pluginName)
-                               }
-                       }
-               }
-       }
-
-       for _, pluginName := range preInstalledPlugins {
+       for _, plugin := range ListRuntimeFiles(RTPlugin) {
                alreadyExists := false
+               pluginName := plugin.Name()
                for _, pl := range loadedPlugins {
                        if pl == pluginName {
                                alreadyExists = true
                                break
                        }
                }
+
                if !alreadyExists {
-                       plugin := "runtime/plugins/" + pluginName + "/" + pluginName + ".lua"
-                       data, err := Asset(plugin)
+                       data, err := plugin.Data()
                        if err != nil {
-                               TermMessage("Error loading pre-installed plugin: " + pluginName)
+                               TermMessage("Error loading plugin: " + pluginName)
                                continue
                        }
                        pluginDef := "\nlocal P = {}\n" + pluginName + " = P\nsetmetatable(" + pluginName + ", {__index = _G})\nsetfenv(1, P)\n"
+
                        if err := L.DoString(pluginDef + string(data)); err != nil {
                                TermMessage(err)
                                continue
                        }
-
                        loadedPlugins = append(loadedPlugins, pluginName)
                }
        }