feat: live filesize (#649)
This commit is contained in:
parent
74317d5c9d
commit
63f74ac069
|
@ -1,25 +1,18 @@
|
||||||
-- Copyright (c) 2020-2021 shadmansaleh
|
-- Copyright (c) 2020-2021 shadmansaleh
|
||||||
-- MIT license, see LICENSE for more details.
|
-- MIT license, see LICENSE for more details.
|
||||||
local function filesize()
|
local function filesize()
|
||||||
local file = vim.fn.expand('%:p')
|
local size = vim.fn.wordcount().bytes
|
||||||
if file == nil or #file == 0 then
|
|
||||||
return ''
|
|
||||||
end
|
|
||||||
|
|
||||||
local size = vim.fn.getfsize(file)
|
local suffixes = { 'b', 'k', 'm', 'g' }
|
||||||
if size <= 0 then
|
|
||||||
return ''
|
|
||||||
end
|
|
||||||
|
|
||||||
local sufixes = { 'b', 'k', 'm', 'g' }
|
|
||||||
|
|
||||||
local i = 1
|
local i = 1
|
||||||
while size > 1024 and i < #sufixes do
|
while size > 1024 and i < #suffixes do
|
||||||
size = size / 1024
|
size = size / 1024
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
return string.format('%.1f%s', size, sufixes[i])
|
local format = i == 1 and '%d%s' or '%.1f%s'
|
||||||
|
return string.format(format, size, suffixes[i])
|
||||||
end
|
end
|
||||||
|
|
||||||
return filesize
|
return filesize
|
||||||
|
|
Loading…
Reference in New Issue