Neovim plugin to automatically adjust
git env vars when syncing dotfiles using the "bare git repo" method
1local Commands = {}
2
3---@type BaredotConfig
4local options
5
6function Commands.set(enable)
7 if enable then
8 vim.env.GIT_WORK_TREE = options.git_work_tree
9 vim.env.GIT_DIR = options.git_dir
10 else
11 vim.env.GIT_WORK_TREE = nil
12 vim.env.GIT_DIR = nil
13 end
14end
15
16function Commands.is_enabled()
17 return vim.env.GIT_DIR ~= nil and vim.env.GIT_WORK_TREE ~= nil
18end
19
20function Commands.toggle()
21 Commands.set(not Commands.is_enabled())
22 Commands.info()
23end
24
25function Commands.info()
26 if Commands.is_enabled() then
27 vim.notify(
28 "Baredot mode on: GIT_DIR=" .. vim.env.GIT_DIR .. " GIT_WORK_TREE=" .. vim.env.GIT_WORK_TREE,
29 vim.log.levels.INFO,
30 { title = "baredot.nvim" }
31 );
32 else
33 vim.notify("Baredot mode off", vim.log.levels.INFO, { title = "baredot.nvim" });
34 end
35end
36
37function Commands.setup(opt)
38 options = opt
39
40 vim.api.nvim_create_user_command("Baredot", function(args)
41 local cmd = vim.trim(args.args or "")
42 if cmd == "toggle" then
43 Commands.toggle()
44 else
45 Commands.info()
46 end
47 end, {
48 desc = "Baredot",
49 nargs = "?",
50 complete = function()
51 return { "info", "toggle" }
52 end
53 })
54end
55
56return Commands