From 5045add053e5707ca46d76c37721246c863780ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=A7=E7=BE=8A=E7=8A=AC=E7=9C=9FQ?= Date: Tue, 6 Jan 2026 00:40:22 +0800 Subject: [PATCH] fix(chezmoi): handle .chezmoiroot in source_dir_path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- lua/lazyvim/plugins/extras/util/chezmoi.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lua/lazyvim/plugins/extras/util/chezmoi.lua b/lua/lazyvim/plugins/extras/util/chezmoi.lua index 201288a4..bc836c1d 100644 --- a/lua/lazyvim/plugins/extras/util/chezmoi.lua +++ b/lua/lazyvim/plugins/extras/util/chezmoi.lua @@ -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, }, {