-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running shell script in statusformatl #1860
Comments
You can customize the status bar with lua code. See the default status plugin in runtime/plugins/status for examples. Also check the |
It seems weirdly phrased from what I can tell, mind giving an example? |
This would actually be quite useful if it was possible to do small inline stuff this way. |
Commands cannot be specified in status line format definitions, but functions in Lua plugins can be registered so that parts with the function name are replaced with the string returned when the function is called. The file at Functions in status line format definitions are called with the buffer being displayed passed in arguments. The content of local micro = import("micro")
function typeicon(buf)
-- getting and returning icon with filetype as key in table (like
-- dictionary in other programming languages)
return ({
-- key is "c", for example
c = "C",
["c++"] = "C++",
shell = "sh"
})[buf:FileType()] or "default"
end
function init()
micro.SetStatusInfoFn("initlua.typeicon")
end The function can be used when specifying the function name like this in settings: "statusformatl": "$(filename) $(initlua.typeicon)" The function would usually be called when the screen is being updated so I do not know if the performance would be fine, but local config = import("micro/config")
local shell = import("micro/shell")
function typeicon(buf)
-- sh ~/.config/micro/typeicon.sh (filetype)
local script = config.ConfigDir .. "/typeicon.sh"
local icon, err = shell.ExecCommand("sh", script, buf:FileType())
if err ~= nil then return "(error)" end
return icon
end I think it is not clear how functions can be registered and used when only looking at the help files. |
Description of the problem or steps to reproduce
I was attempting to try and add file type icons, and at first I thought the
statusformatl
took shell scripting in the sense that$(echo "test")
would yield test... etc etc... But from what I later discovered it seems it's using Lua code? I've hardly played with Lua so I don't know that much, but would there be any way to make it usestdin
from a shell script to put into the status?That way I can easily add my own file type icons...
Specifications
Commit hash: 5044ccf
OS: Linux (Arch)
Terminal: GNOME Terminal
The text was updated successfully, but these errors were encountered: