From a24bca32580f88bc63a1ff15dfacc86673f03a59 Mon Sep 17 00:00:00 2001 From: sammyette Date: Thu, 2 May 2024 22:07:09 -0400 Subject: [PATCH] fix!: get/set env variables via env table this removes the old "virtual global table" which allows getting environment variables via just their names in lua. this means: an environment variable (like TERM) would need to be accessed via the `env` table instead of just using TERM in lua. `TERM` -> `env.TERM` they can also be set via `env.VARIABLE = 'value' --- nature/env.lua | 10 ++++++++++ nature/init.lua | 31 +------------------------------ 2 files changed, 11 insertions(+), 30 deletions(-) create mode 100644 nature/env.lua diff --git a/nature/env.lua b/nature/env.lua new file mode 100644 index 0000000..2d70128 --- /dev/null +++ b/nature/env.lua @@ -0,0 +1,10 @@ +env = {} + +setmetatable(env, { + __index = function(_, k) + return os.getenv(k) + end, + __newindex = function(_, k, v) + os.setenv(k, tostring(v)) + end +}) diff --git a/nature/init.lua b/nature/init.lua index a0579d7..f87b274 100644 --- a/nature/init.lua +++ b/nature/init.lua @@ -24,6 +24,7 @@ require 'nature.opts' require 'nature.vim' require 'nature.runner' require 'nature.hummingbird' +require 'nature.env' local shlvl = tonumber(os.getenv 'SHLVL') if shlvl ~= nil then @@ -32,36 +33,6 @@ else os.setenv('SHLVL', '0') end -do - local virt_G = { } - - setmetatable(_G, { - __index = function (_, key) - local got_virt = virt_G[key] - if got_virt ~= nil then - return got_virt - end - - if type(key) == 'string' then - virt_G[key] = os.getenv(key) - end - return virt_G[key] - end, - - __newindex = function (_, key, value) - if type(value) == 'string' then - os.setenv(key, value) - virt_G[key] = value - else - if type(virt_G[key]) == 'string' then - os.setenv(key, '') - end - virt_G[key] = value - end - end, - }) -end - do local startSearchPath = hilbish.userDir.data .. '/hilbish/start/?/init.lua;' .. hilbish.userDir.data .. '/hilbish/start/?.lua'