include a local file, when it exist #2243
FranklinYu
started this conversation in
Show and tell
Replies: 1 comment
-
Thank you - this is very neat :) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
From time to time I want to have part of my configuration “local”: optional, not checked into version control, modified only locally. Some of the configuration languages have built-in “include” functionality (e.g. shell, tmux, VimL), but some mini-languages don’t. A notable example is the Git-ignore (such a feature has been asked here and there).
Specifically, I want to have part of my
~/.config/git/ignore
checked in, part of it remains local. The solution is to generate the~/.config/git/ignore
from several files (which serve as the source-of-truth). Chezmoi has the helpful template system where I can simply usedot_config/git/ignore.tmpl
, but I came across a problem: where to put the local file?The local file can be placed in the source directory, or the target directory. I decided to go with the source directory, so in my
ignore.tmpl
I haveNotes:
include
requires the file to exist; that’s why I wrapped it in anif
statement.stat
function seems to only accept absolute path, unlikeinclude
, so I have to construct the path withjoinPath
.If, one wants to put the file in target directory, it’s also possible with Chezmoi. Note that target directory isn’t one of the template variables, but we have
.chezmoi.homeDir
, so the template becomesYour mileage may vary.
Beta Was this translation helpful? Give feedback.
All reactions