lualine.nvim/lua/lualine/components/special/vim_var_component.lua
shadmansaleh c9c5e3f9d1 feat: Add type option to hint what type of component is the string
String values for component are way too overloaded . This means lualine
has to make lots of checks to understand how to load a string value
as a component . With type option users can specify exactly what they
want.
2021-08-22 13:54:05 +06:00

20 lines
697 B
Lua

local VarComponent = require('lualine.component'):new()
VarComponent.update_status = function(self)
local component = self.options[1]
-- vim veriable component
-- accepts g:, v:, t:, w:, b:, o, go:, vo:, to:, wo:, bo:
-- filters g portion from g:var
local scope = component:match('[gvtwb]?o?')
-- filters var portion from g:var
local var_name = component:sub(#scope + 2, #component)
-- Displays nothing when veriable aren't present
if not (scope and var_name) then return '' end
local return_val = vim[scope][var_name]
if return_val == nil then return '' end
local ok
ok, return_val = pcall(tostring, return_val)
return ok and return_val or ''
end
return VarComponent