2021-09-20 11:46:38 +00:00
|
|
|
-- Copyright (c) 2020-2021 shadmansaleh
|
|
|
|
-- MIT license, see LICENSE for more details.
|
2021-09-25 17:15:42 +00:00
|
|
|
local M = require('lualine.component'):extend()
|
|
|
|
|
|
|
|
function M:update_status()
|
2021-04-11 08:20:41 +00:00
|
|
|
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
|
2022-01-02 11:38:39 +00:00
|
|
|
local scope = component:match('[gvtwb]?o?')
|
2021-04-11 08:20:41 +00:00
|
|
|
-- filters var portion from g:var
|
|
|
|
local var_name = component:sub(#scope + 2, #component)
|
|
|
|
-- Displays nothing when veriable aren't present
|
2021-09-03 18:28:20 +00:00
|
|
|
if not (scope and var_name) then
|
|
|
|
return ''
|
|
|
|
end
|
2021-08-27 18:32:44 +00:00
|
|
|
-- Support accessing keys within dictionary
|
2021-10-22 04:57:04 +00:00
|
|
|
-- https://github.com/nvim-lualine/lualine.nvim/issues/25#issuecomment-907374548
|
2021-08-27 18:32:44 +00:00
|
|
|
local name_chunks = vim.split(var_name, '%.')
|
|
|
|
local return_val = vim[scope][name_chunks[1]]
|
2021-09-03 18:28:20 +00:00
|
|
|
for i = 2, #name_chunks do
|
|
|
|
if return_val == nil then
|
|
|
|
break
|
|
|
|
end
|
2021-08-27 18:32:44 +00:00
|
|
|
return_val = return_val[name_chunks[i]]
|
|
|
|
end
|
2021-09-03 18:28:20 +00:00
|
|
|
if return_val == nil then
|
|
|
|
return ''
|
|
|
|
end
|
2021-04-11 08:20:41 +00:00
|
|
|
local ok
|
|
|
|
ok, return_val = pcall(tostring, return_val)
|
2021-08-20 12:32:56 +00:00
|
|
|
return ok and return_val or ''
|
2021-04-11 08:20:41 +00:00
|
|
|
end
|
|
|
|
|
2021-09-25 17:15:42 +00:00
|
|
|
return M
|