xvzc / chezmoi.nvim

Chezmoi plugin for neovim
MIT License
73 stars 3 forks source link

[FEATURE REQUEST] recently edited by chezmoi #9

Closed azinsharaf closed 5 months ago

azinsharaf commented 6 months ago

is there any command that can list the files "recently" edited by chezmoi, similar to telescope.builtin.oldfiles() in telescope?

azinsharaf commented 6 months ago

well, telescope.builtin.oldfiles() already shows me the files edited in chezmoi but opening them and editing doesn't sync the file. I tried the autocmd in readme.md but couldn't make it to work.

xvzc commented 6 months ago

Did you lazy load this plugin?

azinsharaf commented 5 months ago

yes the plugin is loaded. when i edit via :chezmoiedit everything works fine but when i edit outside of :chezmoiedit (for example opening a file directly with nvim nvim "C:\Users\asharaf\.local\share\chezmoi\dot_config\nvim\init.lua") then sync won't happen. this is my config on windows:

return {
    "xvzc/chezmoi.nvim",
    lazy = false,
    dependencies = { "nvim-lua/plenary.nvim" },
    config = function()
        require("chezmoi").setup({
            -- your configurations
            edit = {
                watch = true, -- Set true to automatically apply on save.
                force = true, -- Set true to force apply. Works only when watch = true.
            },
            notification = {
                on_open = true, -- vim.notify when start editing chezmoi-managed file.
                on_apply = true, -- vim.notify on apply.
            },
            telescope = {
                select = { "<CR>" },
            },
        })

        -- Autocmd for Chezmoi
        vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, {
            pattern = { os.getenv("USERPROFILE") .. "/.local/share/chezmoi/*" },
            callback = function()
                vim.schedule(require("chezmoi.commands.__edit").watch)
            end,
        })
    end,
}
xvzc commented 5 months ago

Maybe because your path string contains / instead of \\ which is the path separator for windows system? By the way, I need to tell you that it's not throughly tested on windows system.

azinsharaf commented 5 months ago

still doesn't trigger the sync using \ (double back slash) no problem, i will use :chezmoiedit for now.

        -- Autocmd for Chezmoi
        vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, {
            pattern = { os.getenv("USERPROFILE") .. "\\.local\\share\\chezmoi\\*" },
            callback = function()
                vim.schedule(require("chezmoi.commands.__edit").watch)
            end,
        })
joncrangle commented 1 month ago

I see this issue is closed, but I was able to get the autocmd working with the following. I use scoop to install packages on Windows, so the path might be different for other scoop install methods.

vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile' }, {
        pattern = {
          (vim.fn.has 'win32' == 1 and os.getenv 'USERPROFILE' .. '/AppData/Local/chezmoi/*' or os.getenv 'HOME' .. '/.local/share/chezmoi/*'),
        },
        callback = function()
          vim.schedule(require('chezmoi.commands.__edit').watch)
        end,
      })
azinsharaf commented 1 month ago

i closed it becasue couldn't fix it. I wil test your snippet by tomorrow.

azinsharaf commented 1 month ago

@joncrangle what is this folder? what do you have inside of it? '/AppData/Local/chezmoi/*'

joncrangle commented 1 month ago

@joncrangle what is this folder? what do you have inside if it? '/AppData/Local/chezmoi/*'

This is the directory in Windows that contains my chezmoi source files/templates. On Mac and Linux the directory for me is ~/.local/share/chezmoi, but on Windows it's %USERPROFILE%/AppData/Local/chezmoi (or %LOCALAPPDATA%/chezmoi), I installed chezmoi on Windows with scoop so I'm not sure if the default directory is different with other installation methods.

azinsharaf commented 1 month ago

i changed the path accordingly but still doesn't trigger the sync. for now i use this keymap to edit the chezmoi fiels: keymap.set("n", "<leader>fc", telescope.extensions.chezmoi.find_files, { desc = "Find chezmoi files" })