shadmansaleh c8750a35e0 enhance: allow components to be functions too (#81)
Some components like hostname, progress are so simple that
the component class setup is just unnecessary boilerplate.
Allowing them to be function simplifies things.
With this you can put your regular component functions in
~/.config/nvim/lua/lualine/components/ folder and treat then as
regular lualine components just like 'mode' or 'branch'.
Hopefully this will help lualine plugins grow.
2021-10-11 16:41:25 +06:00

26 lines
494 B
Lua

-- Copyright (c) 2020-2021 shadmansaleh
-- MIT license, see LICENSE for more details.
local function filesize()
local file = vim.fn.expand '%:p'
if file == nil or #file == 0 then
return ''
end
local size = vim.fn.getfsize(file)
if size <= 0 then
return ''
end
local sufixes = { 'b', 'k', 'm', 'g' }
local i = 1
while size > 1024 and i < #sufixes do
size = size / 1024
i = i + 1
end
return string.format('%.1f%s', size, sufixes[i])
end
return filesize