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()
|
2021-09-03 18:28:20 +00:00
|
|
|
local file = vim.fn.expand '%:p'
|
|
|
|
if file == nil or #file == 0 then
|
|
|
|
return ''
|
|
|
|
end
|
2021-09-03 10:16:10 +00:00
|
|
|
|
|
|
|
local size = vim.fn.getfsize(file)
|
2021-09-03 18:28:20 +00:00
|
|
|
if size <= 0 then
|
|
|
|
return ''
|
|
|
|
end
|
2021-09-03 10:16:10 +00:00
|
|
|
|
2021-09-03 18:28:20 +00:00
|
|
|
local sufixes = { 'b', 'k', 'm', 'g' }
|
2021-09-03 10:16:10 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-10-10 16:43:00 +00:00
|
|
|
return filesize
|