2021-02-15 18:09:12 +00:00
|
|
|
-- Copyright (c) 2020-2021 shadmansaleh
|
2021-02-13 00:03:57 +00:00
|
|
|
-- MIT license, see LICENSE for more details.
|
2021-04-11 08:20:41 +00:00
|
|
|
local FileName = require('lualine.component'):new()
|
|
|
|
|
|
|
|
FileName.new = function(self, options, child)
|
2021-04-20 03:02:21 +00:00
|
|
|
local new_instance = self._parent:new(options, child or FileName)
|
2021-04-20 16:25:25 +00:00
|
|
|
local default_symbols = {modified = '[+]', readonly = '[-]'}
|
2021-05-09 21:11:18 +00:00
|
|
|
new_instance.options.symbols = vim.tbl_extend('force', default_symbols,
|
|
|
|
new_instance.options.symbols or
|
|
|
|
{})
|
2021-04-11 08:20:41 +00:00
|
|
|
|
2021-02-15 18:09:12 +00:00
|
|
|
-- setting defaults
|
2021-04-20 03:02:21 +00:00
|
|
|
if new_instance.options.file_status == nil then
|
|
|
|
new_instance.options.file_status = true
|
2021-04-11 08:20:41 +00:00
|
|
|
end
|
2021-04-20 03:02:21 +00:00
|
|
|
if new_instance.options.shorten == nil then
|
|
|
|
new_instance.options.shorten = true
|
2021-04-11 08:20:41 +00:00
|
|
|
end
|
2021-04-20 03:02:21 +00:00
|
|
|
if new_instance.options.full_path == nil then
|
|
|
|
new_instance.options.full_path = false
|
2021-04-11 08:20:41 +00:00
|
|
|
end
|
2021-02-15 18:09:12 +00:00
|
|
|
|
2021-04-20 03:02:21 +00:00
|
|
|
return new_instance
|
2021-04-11 08:20:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
FileName.update_status = function(self)
|
|
|
|
local data = vim.fn.expand('%:p')
|
|
|
|
if not self.options.full_path then
|
|
|
|
data = vim.fn.expand('%:t')
|
|
|
|
elseif self.options.shorten then
|
|
|
|
data = vim.fn.expand('%:~:.')
|
|
|
|
end
|
|
|
|
|
|
|
|
if data == '' then
|
|
|
|
data = '[No Name]'
|
|
|
|
elseif vim.fn.winwidth(0) <= 84 or #data > 40 then
|
|
|
|
data = vim.fn.pathshorten(data)
|
|
|
|
end
|
2021-02-15 18:09:12 +00:00
|
|
|
|
2021-04-11 08:20:41 +00:00
|
|
|
if self.options.file_status then
|
|
|
|
if vim.bo.modified then
|
2021-04-20 16:25:25 +00:00
|
|
|
data = data .. self.options.symbols.modified
|
2021-04-11 08:20:41 +00:00
|
|
|
elseif vim.bo.modifiable == false or vim.bo.readonly == true then
|
2021-04-20 16:25:25 +00:00
|
|
|
data = data .. self.options.symbols.readonly
|
2021-02-15 18:09:12 +00:00
|
|
|
end
|
|
|
|
end
|
2021-04-11 08:20:41 +00:00
|
|
|
return data
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
|
|
|
|
2021-04-11 08:20:41 +00:00
|
|
|
return FileName
|