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.toggle() 17 if vim.env.GIT_DIR == nil or vim.env.GIT_WORK_TREE == nil then 18 Commands.set(true) 19 else 20 Commands.set(false) 21 end 22 Commands.info() 23end 24 25function Commands.info() 26 if vim.env.GIT_DIR == nil or vim.env.GIT_WORK_TREE == nil then 27 vim.notify("Baredot mode off", vim.log.levels.INFO, { title = "baredot.nvim" }); 28 else 29 vim.notify( 30 "Baredot mode on: GIT_DIR=" .. vim.env.GIT_DIR .. " GIT_WORK_TREE=" .. vim.env.GIT_WORK_TREE, 31 vim.log.levels.INFO, 32 { title = "baredot.nvim" } 33 ); 34 end 35end 36 37function Commands.setup(opt) 38 options = opt 39 40 vim.api.nvim_create_user_command("BaredotInfo", Commands.info, { desc = "BaredotInfo" }) 41 vim.api.nvim_create_user_command("BaredotToggle", Commands.toggle, { desc = "BaredotToggle" }) 42end 43 44return Commands