]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/rtfiles.go
Add cd and pwd commands to change the working dir
[micro.git] / cmd / micro / rtfiles.go
index ac03b7a29bf40ed96f22f0a0d49e2a74bc583053..91bafa08fc75c2eb2fa9314ef7ccf1e8964ee02c 100644 (file)
@@ -11,6 +11,7 @@ const (
        RTColorscheme = "colorscheme"
        RTSyntax      = "syntax"
        RTHelp        = "help"
+       RTPlugin      = "plugin"
 )
 
 // RuntimeFile allows the program to read runtime data like colorschemes or syntax files
@@ -121,6 +122,26 @@ func InitRuntimeFiles() {
        add(RTColorscheme, "colorschemes", "*.micro")
        add(RTSyntax, "syntax", "*.micro")
        add(RTHelp, "help", "*.md")
+
+       // Search configDir for plugin-scripts
+       files, _ := ioutil.ReadDir(filepath.Join(configDir, "plugins"))
+       for _, f := range files {
+               if f.IsDir() {
+                       scriptPath := filepath.Join(configDir, "plugins", f.Name(), f.Name()+".lua")
+                       if _, err := os.Stat(scriptPath); err == nil {
+                               AddRuntimeFile(RTPlugin, realFile(scriptPath))
+                       }
+               }
+       }
+
+       if files, err := AssetDir("runtime/plugins"); err == nil {
+               for _, f := range files {
+                       scriptPath := path.Join("runtime/plugins", f, f+".lua")
+                       if _, err := AssetInfo(scriptPath); err == nil {
+                               AddRuntimeFile(RTPlugin, assetFile(scriptPath))
+                       }
+               }
+       }
 }
 
 // PluginReadRuntimeFile allows plugin scripts to read the content of a runtime file
@@ -144,12 +165,12 @@ func PluginListRuntimeFiles(fileType string) []string {
 }
 
 // PluginAddRuntimeFile adds a file to the runtime files for a plugin
-func PluginAddRuntimeFile(plugin, filetype, path string) {
-       fullpath := filepath.Join(configDir, "plugins", plugin, path)
+func PluginAddRuntimeFile(plugin, filetype, filePath string) {
+       fullpath := filepath.Join(configDir, "plugins", plugin, filePath)
        if _, err := os.Stat(fullpath); err == nil {
                AddRuntimeFile(filetype, realFile(fullpath))
        } else {
-               fullpath = path.Join("runtime", "plugins", plugin, path)
+               fullpath = path.Join("runtime", "plugins", plugin, filePath)
                AddRuntimeFile(filetype, assetFile(fullpath))
        }
 }