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)
|
|
|
|
local new_instence = self._parent:new(options, child or FileName)
|
|
|
|
|
2021-02-15 18:09:12 +00:00
|
|
|
-- setting defaults
|
2021-04-11 08:20:41 +00:00
|
|
|
if new_instence.options.file_status == nil then
|
|
|
|
new_instence.options.file_status = true
|
|
|
|
end
|
|
|
|
if new_instence.options.shorten == nil then
|
|
|
|
new_instence.options.shorten = true
|
|
|
|
end
|
|
|
|
if new_instence.options.full_path == nil then
|
|
|
|
new_instence.options.full_path = false
|
|
|
|
end
|
2021-02-15 18:09:12 +00:00
|
|
|
|
2021-04-11 08:20:41 +00:00
|
|
|
return new_instence
|
|
|
|
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
|
|
|
|
data = data .. '[+]'
|
|
|
|
elseif vim.bo.modifiable == false or vim.bo.readonly == true then
|
|
|
|
data = data .. '[-]'
|
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
|