2021-09-03 10:16:10 +00:00
|
|
|
-- Copyright (c) 2020-2021 shadmansaleh
|
|
|
|
-- MIT license, see LICENSE for more details.
|
2021-10-10 16:43:00 +00:00
|
|
|
local function filesize()
|
2022-05-07 03:53:33 +00:00
|
|
|
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
|
2021-09-03 10:16:10 +00:00
|
|
|
|
2022-04-14 04:41:59 +00:00
|
|
|
local suffixes = { 'b', 'k', 'm', 'g' }
|
2021-09-03 10:16:10 +00:00
|
|
|
|
|
|
|
local i = 1
|
2022-04-14 04:41:59 +00:00
|
|
|
while size > 1024 and i < #suffixes do
|
2021-09-03 10:16:10 +00:00
|
|
|
size = size / 1024
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
|
2022-04-14 04:41:59 +00:00
|
|
|
local format = i == 1 and '%d%s' or '%.1f%s'
|
|
|
|
return string.format(format, size, suffixes[i])
|
2021-09-03 10:16:10 +00:00
|
|
|
end
|
|
|
|
|
2021-10-10 16:43:00 +00:00
|
|
|
return filesize
|