fix(chezmoi): handle .chezmoiroot in source_dir_path

Add support for .chezmoiroot to configure source directory.## Problem

  When users have a .chezmoiroot file in their chezmoi source directory, the current chezmoi#source_dir_path setting doesn't include the root subdirectory. This causes chezmoi.vim's filetype detection to fail for files in .chezmoiscripts/ and other special directories.

  For example, with .chezmoiroot containing home:
  - Current: ~/.local/share/chezmoi
  - Expected: ~/.local/share/chezmoi/home

  ## Solution

  Read .chezmoiroot file if it exists and append its content to the source path, matching chezmoi.vim's built-in detection behavior.

  ## Testing

  Verified with:
  - .chezmoiscripts/run_once_before_*.sh.tmpl → sh.chezmoitmpl 
  - dot_config/fish/config.fish.tmpl → fish.chezmoitmpl
This commit is contained in:
牧羊犬真Q 2026-01-06 00:40:22 +08:00 committed by GitHub
parent c64a61734f
commit 5045add053
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -55,7 +55,18 @@ return {
"alker0/chezmoi.vim",
init = function()
vim.g["chezmoi#use_tmp_buffer"] = 1
vim.g["chezmoi#source_dir_path"] = vim.env.HOME .. "/.local/share/chezmoi"
-- Handle .chezmoiroot for users who organize source files in subdirectories
local source = vim.env.HOME .. "/.local/share/chezmoi"
local root_file = source .. "/.chezmoiroot"
local f = io.open(root_file, "r")
if f then
local root = f:read("*l")
f:close()
if root and root ~= "" then
source = source .. "/" .. vim.trim(root)
end
end
vim.g["chezmoi#source_dir_path"] = source
end,
},
{