Skip to content

Commit

Permalink
feat: Adding "is_enabled" lua function
Browse files Browse the repository at this point in the history
  • Loading branch information
ejrichards committed Jun 17, 2024
1 parent 18cad60 commit 9fd8094
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 8 additions & 8 deletions lua/baredot/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions lua/baredot/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9fd8094

Please sign in to comment.