Neovim plugin to automatically adjust git env vars when syncing dotfiles using the "bare git repo" method
at master 1.2 kB view raw
1local commands = require("baredot.commands") 2local scan = require("baredot.scan") 3 4local Baredot = {} 5 6---@class BaredotConfig 7local defaults = { 8 git_dir = "~/.cfg", 9 git_work_tree = "~", 10 disable_pattern = "%.git" 11} 12 13---@param opt? BaredotConfig 14function Baredot.setup(opt) 15 ---@type BaredotConfig 16 local options = vim.tbl_deep_extend("force", {}, defaults, opt or {}) 17 18 options.git_dir = vim.fn.expand(options.git_dir) 19 options.git_work_tree = vim.fn.expand(options.git_work_tree) 20 21 commands.setup(options) 22 scan.setup(options) 23 24 if scan.in_work_tree_no_dot_git() then 25 commands.set(true) 26 end 27 28 local group = vim.api.nvim_create_augroup("baredot", { clear = true }) 29 vim.api.nvim_create_autocmd("DirChanged", { 30 group = group, 31 desc = "Baredot: scan for .git", 32 callback = function() 33 if vim.v.event.scope == "global" then 34 commands.set(scan.in_work_tree_no_dot_git()) 35 end 36 end, 37 }) 38end 39 40function Baredot.info() 41 return commands.info() 42end 43---@param enable boolean 44function Baredot.set(enable) 45 return commands.set(enable) 46end 47function Baredot.toggle() 48 return commands.toggle() 49end 50---@return boolean 51function Baredot.is_enabled() 52 return commands.is_enabled() 53end 54 55return Baredot