alker0 / chezmoi.vim

Highlight dotfiles you manage with chezmoi.
Other
119 stars 3 forks source link

Question: How to make this plugin work with kickstart.nvim #65

Closed benjaminbauer closed 11 months ago

benjaminbauer commented 12 months ago

I am trying to get his plugin to work in Neovim 0.9 with the popular https://github.com/nvim-lua/kickstart.nvim

I am using the proposed fix in https://github.com/alker0/chezmoi.vim/issues/57#issuecomment-1425027170.

What does not work: the filetype detection: template gets detected. When I manually set the filetype in the buffer to e.g. sh.chezmoitmpl on a file called run_once_setup.sh.tmpl it works.

I know this kind of support is out of scope for this plugin. Any pointers are still appreciated!

Also: Consider to include the config for lazy.nvim in the README

alker0 commented 12 months ago

Thank you for your reporting.

In my Neovim environment, trying kickstart.nvim doesn't reproduce currently. I cloned kickstart.nvim and inserted the following lines as the first plugin of lazy.nvim. That's all I did and get highlighting for chezmoi template.

require('lazy').setup({
  -- NOTE: First, some plugins that don't require any configuration

  -- ==== Inserted lines ====
  {
    'alker0/chezmoi.vim',
    lazy = false,
    init = function(plugin)
      vim.g['chezmoi#use_tmp_buffer'] = true
    end,
  },

  -- ...other default
})

And nvim ~/.local/share/chezmoi/run_once_setup.sh.tmpl showes: kickstart-screenshot

It may come from failing to integrate between this plugin and other additional plugins by your custom. Please try toggling On/Off each plugins with enabled = false plugin option of lazy.nvim, and tell whether any works correctly.


Your Also: advice is exactly right. The README has to guide also lazy.nvim users to making this plugin work. After resolving this issue, I will add a config sample with considering resolving steps of that.

benjaminbauer commented 12 months ago

Thanks @alker0! I reverted my init.lua to the current HEAD of kickstart and added your lines. I still get the same result:

image
NVIM v0.9.2
Build type: RelWithDebInfo
LuaJIT 2.1.1692716794

Does the plugin rely on anything external for the filetype detection?

alker0 commented 12 months ago

Thank you for trying to reset your config. This issue doesn't seem to come from a plugins combination.

Does the plugin rely on anything external for the filetype detection?

No, it doesn't depend any externals unless you enable the option g:chezmoi#use_external. If your chezmoi-managed directory isn't the default path (e.g. ~/.local/share/chezmoi/), you need to tell the plugin there with the g:chezmoi#source_dir_path option like this:

  {
    'alker0/chezmoi.vim',
    lazy = false,
    init = function(plugin)
      vim.g['chezmoi#use_tmp_buffer'] = true
      -- Specify your chezmoi source dir path instead of this example path.
      vim.g['g:chezmoi#source_dir_path'] = os.getenv('HOME') .. '/dotfiles'
    end,
  },

Please try it if you placed the source directory where isn't default. If not, call these commands in editing run_once_setup.sh.tmpl and tell me each output.

alker0 commented 12 months ago

If you care about privacy of your environment, you have to tell me only :echo isdirectory(...) commands of above.

benjaminbauer commented 11 months ago

Thanks! It was the g:chezmoi#source_dir_path. Two pointers wrt to your snippet:

  1. init = function(plugin): plugin is unused and can be ommited
  2. vim.g['g:chezmoi#source_dir_path'] =: it is supposed to be vim.g["chezmoi#source_dir_path"]

Can the plugin be adapted to pick up the sourceDir from chezmoi instead of (I assume) a static list of paths? chezmoi data can deliver the actual sourceDir

benjaminbauer commented 11 months ago

FWIW: For kickstart.nvim users that do want to minimize changes to init.lua, the chezmoi plugin is also perfectly happy when one puts this in a file in the "standard" kickstart custom plugin path nvim/lua/custom/plugins/

return {
   'alker0/chezmoi.vim',
   lazy = false,
   init = function()
     vim.g['chezmoi#use_tmp_buffer'] = true
      -- adapt to your actual source dir path IF not using the standard path
      -- see `chezmoi data | grep sourceDir`
     vim.g["chezmoi#source_dir_path"] = vim.fn.expand("$HOME/dotfiles") 
   end,
 }
alker0 commented 11 months ago

Great:tada:

Thank you for some pointers. Sure, the plugin argument and the g: prefix are unnecessary. Also vim.fn.expand(...) is definitely better than os.getenv(...).

Can the plugin be adapted to pick up the sourceDir from chezmoi instead of (I assume) a static list of paths?

Please try to add vim.g['chezmoi#use_external'] = 1 like other plugin options. Setting g:chezmoi#use_external at 1 should automatically tell the plugin your source dir path by calling chezmoi source-path.

You can get more details from the Option section of README.

alker0 commented 11 months ago

the chezmoi plugin is also perfectly happy when one puts this in a file in the "standard" kickstart custom plugin path nvim/lua/custom/plugins/

Oh, I didn't know that cool hack. We need to add only { import = 'custom.plugins' }, as if this is the last plugin of lazy.nvim. If we use a plugin manager other than lazy.nvim, we can also apply it by little change because it's builtin feature of lua language. However in README, it shouldn't need to give that for getting work of the plugin.

Thank you a lot for your helping improvement of documentation.

benjaminbauer commented 11 months ago

Very welcome!

vim.g['chezmoi#use_external'] = 1 instead of setting chezmoi#source_dir_path also works. The docs mention, that using chezmoi#use_external is slower. So I guess setting chezmoi#source_dir_path is the better option in the scenario