Giter Site home page Giter Site logo

Comments (9)

cweagans avatar cweagans commented on May 24, 2024 1

It took me a bit to get back to this -- thanks for your patience! I tried this out in cweagans/dotfiles@d672172 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,
})

from chezmoi.nvim.

xvzc avatar xvzc commented on May 24, 2024

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?

from chezmoi.nvim.

cweagans avatar cweagans commented on May 24, 2024

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.

from chezmoi.nvim.

xvzc avatar xvzc commented on May 24, 2024

Can i do this for you then? I have been doing some refactoring and i think i can add this feature too.

from chezmoi.nvim.

cweagans avatar cweagans commented on May 24, 2024

Sure! Thank you! Glad to test whenever!! :)

from chezmoi.nvim.

xvzc avatar xvzc commented on May 24, 2024

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.

from chezmoi.nvim.

xvzc avatar xvzc commented on May 24, 2024

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.

local status_err = nil
status.execute {
args = {
"--source-path",
source_path,
},
on_stderr = function(_, data)
status_err = data
end,
}
if status_err then
notify.warn(status_err)
return
end

Please let me know if you got any suggestion or better idea!

from chezmoi.nvim.

xvzc avatar xvzc commented on May 24, 2024

@cweagans Do you mind if i close this issue if you don't have any opinion?

from chezmoi.nvim.

cweagans avatar cweagans commented on May 24, 2024

Not at all!

from chezmoi.nvim.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.