micro icon indicating copy to clipboard operation
micro copied to clipboard

Accessing plugin directory

Open deliciouslytyped opened this issue 4 years ago • 4 comments

I'm not sure if I missed something in the docs; is there a better way to access the path of a plugin than hard coding it with config.ConfigDir .. "/plug/mypluginnamehere"?

deliciouslytyped avatar Jan 14 '21 05:01 deliciouslytyped

I'm reviving Palettero and trying to find a way to load configs from its plugin directory without hardcoding the path. AddRuntimeFilesFromDirectory looks tantalizingly close but ListRuntimeFiles only returns the basename and contents (might be enough anyway) without full path.

@dmaluka @JoeKar Is there another recommended way? You're the most active lately and wondered who might know. I checked Discussions and Gitter but it's inactive.

texastoland avatar Apr 25 '24 20:04 texastoland

I'm afraid AddRuntimeFilesFromDirectory and friends are not what you need. They only deal with micro's specific file formats (RTColorscheme, RTSyntax, RTHelp, RTPlugin), not with arbitrary config files.

is there a better way to access the path of a plugin than hard coding it with config.ConfigDir .. "/plug/mypluginnamehere"

Since micro allows using Go filepath package from lua, I suppose you could do that in a slightly more elegant and portable way: filepath.Join(config.ConfigDir, "plug", "mypluginnamehere").

dmaluka avatar Apr 26 '24 01:04 dmaluka

They only deal with micro's specific file formats (RTColorscheme, RTSyntax, RTHelp, RTPlugin), not with arbitrary config files.

I haven't tested yet but arbitrary formats can be created with NewRTFiletype. Using its file contents may work for my specific use case.

I suppose you could do that in a slightly more elegant and portable way: filepath.Join(config.ConfigDir, "plug", "mypluginnamehere").

It doesn't resolve the underlying issue. New users (from personal experience) install by cloning (for example old issues about symlinking plugins) because pluginrepos is under-documented. But plugin repos are usually prefixed with micro- and sometimes suffixed with -plugin. The hard coded path would fail.

texastoland avatar Apr 26 '24 04:04 texastoland

I haven't tested yet but arbitrary formats can be created with NewRTFiletype. Using its file contents may work for my specific use case.

Hmm, interesting, I wasn't aware of that. You can try.

dmaluka avatar Apr 26 '24 10:04 dmaluka