As the title suggest I try to display the total of loaded lazy plugins in the statusline. I tried to use the function stats from the stats.lua
file without success.
I'm not sure did i understand correctly but here is how to show plugin number in status line or with lualine.
Read lazy-lock.json. File where lazy stores data about plugins.
local function plugin_num()
local count = 0
local path = vim.fn.stdpath("config") .. "/lazy-lock.json"
local file = io.open(path, "r")
if not file then
print("File not found")
else
local content = file:read("a")
local status, json = pcall(vim.fn.json_decode, content)
if status then
for _, _ in pairs(json) do
count = count + 1
end
else
print("failed decoding json")
end
file:close()
return count
end
end
Show it on status line
vim.cmd("set statusline+=" .. plugin_num())
Show it using lualine
sections = {
lualine_x = { plugin_num }
},