Closed cweagans closed 5 months ago
Ah, yeah i've also thought about it, but i think we should just provide the callback function so that users can set it properly with nvim_create_autocmd. What do you think about this?
That'd work. I suppose I don't care how automatic it is - just that there is a way to automatically sync whenever I edit stuff in my chezmoi dir.
Can i do this for you then? I have been doing some refactoring and i think i can add this feature too.
Sure! Thank you! Glad to test whenever!! :)
I think it is almost done. Currently testing on refactor
branch, and my configuration is now like below
require("chezmoi").setup({
edit = {
watch = true,
force = true,
},
notification = {
on_open = false,
on_save = true,
on_watch = true,
},
})
vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, {
pattern = { os.getenv("HOME") .. "/.local/share/chezmoi/*" },
callback = function()
-- invoke with vim.schedule() for better startup time
vim.schedule(require("chezmoi.commands.__edit").watch)
end,
})
Please test the feature on the refactor
branch if you ever get a chance.
It took me a bit to get back to this -- thanks for your patience! I tried this out in https://github.com/cweagans/dotfiles/commit/d67217254c2cd587e2d333dfe4cf97735da78cfb and it worked really really well! This is exactly what I had in mind and it's flexible enough for other people to define their own workflows too.
I think my only feedback would be to maybe have something in the plugin that runs chezmoi source-path
in the background to get the Chezmoi source. That way, the autocommand could look something like this instead:
vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, {
pattern = { require("chezmoi").source_path },
callback = function()
-- invoke with vim.schedule() for better startup time
vim.schedule(require("chezmoi.commands.__edit").watch)
end,
})
Good point. I've actually also tried it, but i thought assigning the result of chezmoi.source_path
to the autocmd pattern
required more lines of code. Furthermore, it will make our neovim take slightly more time during the startup since chezmoi.source_path
returns a list of exact filenames(absolute paths) rather than a pattern strings. It's true that we have to at least check if the file is really a chezmoi managed file, in that case we can do some additional check in watch()
function like below; In this commit, i've used chezmoi.status
.
Please let me know if you got any suggestion or better idea!
@cweagans Do you mind if i close this issue if you don't have any opinion?
Not at all!
Thanks for putting this together! I'm probably gonna start using this pretty regularly.
Would you be interested in a pull request to automatically treat anything in
chezmoi source-path
as a Chezmoi file? That way, I canchezmoi cd
, thennvim .
, start editing, and have stuff applied automatically. Right now, it only applies changes if I:ChezmoiEdit ~/path/to/my/file
.