From 276ba5d19ebc275a3a4accc1a335cb8f3dbc480e Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Sat, 28 Aug 2021 00:32:44 +0600 Subject: [PATCH] feat: Support indexing dictionaries in var components --- lua/lualine/components/special/vim_var_component.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lua/lualine/components/special/vim_var_component.lua b/lua/lualine/components/special/vim_var_component.lua index 53e3dbd..b318f17 100644 --- a/lua/lualine/components/special/vim_var_component.lua +++ b/lua/lualine/components/special/vim_var_component.lua @@ -9,7 +9,14 @@ VarComponent.update_status = function(self) 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] + -- Support accessing keys within dictionary + -- https://github.com/shadmansaleh/lualine.nvim/issues/25#issuecomment-907374548 + local name_chunks = vim.split(var_name, '%.') + local return_val = vim[scope][name_chunks[1]] + for i=2,#name_chunks do + if return_val == nil then break end + return_val = return_val[name_chunks[i]] + end if return_val == nil then return '' end local ok ok, return_val = pcall(tostring, return_val)