diff --git a/README.md b/README.md index ab89fa5..1722d9d 100644 --- a/README.md +++ b/README.md @@ -46,5 +46,6 @@ lazy.nvim ## Functions - `require("baredot").info()` - Print current status +- `require("baredot").is_enabled()` - Returns current status as boolean - `require("baredot").toggle()` - Manually toggle the env vars on / off - `require("baredot").set(boolean)` - Set the env vars on / off diff --git a/lua/baredot/commands.lua b/lua/baredot/commands.lua index 71aa1ca..594a5a3 100644 --- a/lua/baredot/commands.lua +++ b/lua/baredot/commands.lua @@ -13,24 +13,24 @@ function Commands.set(enable) end end +function Commands.is_enabled() + return vim.env.GIT_DIR ~= nil and vim.env.GIT_WORK_TREE ~= nil +end + function Commands.toggle() - if vim.env.GIT_DIR == nil or vim.env.GIT_WORK_TREE == nil then - Commands.set(true) - else - Commands.set(false) - end + Commands.set(not Commands.is_enabled()) Commands.info() end function Commands.info() - if vim.env.GIT_DIR == nil or vim.env.GIT_WORK_TREE == nil then - vim.notify("Baredot mode off", vim.log.levels.INFO, { title = "baredot.nvim" }); - else + if Commands.is_enabled() then vim.notify( "Baredot mode on: GIT_DIR=" .. vim.env.GIT_DIR .. " GIT_WORK_TREE=" .. vim.env.GIT_WORK_TREE, vim.log.levels.INFO, { title = "baredot.nvim" } ); + else + vim.notify("Baredot mode off", vim.log.levels.INFO, { title = "baredot.nvim" }); end end diff --git a/lua/baredot/init.lua b/lua/baredot/init.lua index 1282672..b6c736d 100644 --- a/lua/baredot/init.lua +++ b/lua/baredot/init.lua @@ -47,5 +47,9 @@ end function Baredot.toggle() return commands.toggle() end +---@return boolean +function Baredot.is_enabled() + return commands.is_enabled() +end return Baredot