From 63f74ac06978cead7cd0cbbb65c80bcda2eede41 Mon Sep 17 00:00:00 2001 From: David van Munster <39461169+dmun@users.noreply.github.com> Date: Thu, 14 Apr 2022 06:41:59 +0200 Subject: [PATCH] feat: live filesize (#649) --- lua/lualine/components/filesize.lua | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/lua/lualine/components/filesize.lua b/lua/lualine/components/filesize.lua index ba1818b..1b3add3 100644 --- a/lua/lualine/components/filesize.lua +++ b/lua/lualine/components/filesize.lua @@ -1,25 +1,18 @@ -- 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.wordcount().bytes - local size = vim.fn.getfsize(file) - if size <= 0 then - return '' - end - - local sufixes = { 'b', 'k', 'm', 'g' } + local suffixes = { 'b', 'k', 'm', 'g' } local i = 1 - while size > 1024 and i < #sufixes do + while size > 1024 and i < #suffixes do size = size / 1024 i = i + 1 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 return filesize