feat: add new filesize component
This commit is contained in:
parent
8b4f70817c
commit
b3c5c4403c
|
@ -186,6 +186,7 @@ sections = {lualine_a = {'mode'}}
|
|||
* `encoding` (file encoding)
|
||||
* `fileformat` (file format)
|
||||
* `filename`
|
||||
* `filesize`
|
||||
* `filetype`
|
||||
* `hostname`
|
||||
* `location` (location in file in line:column format)
|
||||
|
|
|
@ -128,6 +128,7 @@ Available components~
|
|||
* |encoding| (file encoding)
|
||||
* |fileformat| (file format)
|
||||
* |filename|
|
||||
* |filesize|
|
||||
* |filetype|
|
||||
* |hostname|
|
||||
* |location| (location in file in line:column format)
|
||||
|
|
|
@ -116,22 +116,7 @@ ins_left {
|
|||
|
||||
ins_left {
|
||||
-- filesize component
|
||||
function()
|
||||
local function format_file_size(file)
|
||||
local size = vim.fn.getfsize(file)
|
||||
if size <= 0 then return '' end
|
||||
local sufixes = {'b', 'k', 'm', 'g'}
|
||||
local i = 1
|
||||
while size > 1024 do
|
||||
size = size / 1024
|
||||
i = i + 1
|
||||
end
|
||||
return string.format('%.1f%s', size, sufixes[i])
|
||||
end
|
||||
local file = vim.fn.expand('%:p')
|
||||
if string.len(file) == 0 then return '' end
|
||||
return format_file_size(file)
|
||||
end,
|
||||
'filesize',
|
||||
condition = conditions.buffer_not_empty
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
-- Copyright (c) 2020-2021 shadmansaleh
|
||||
-- MIT license, see LICENSE for more details.
|
||||
local M = require('lualine.component'):new()
|
||||
|
||||
M.update_status = function()
|
||||
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 M
|
Loading…
Reference in New Issue