Skip to content

Support ignoring files in the source directory (e.g., under .chezmoiexternals/) #4733

@sigprof

Description

@sigprof

Is your feature request related to a problem? Please describe.

Currently there is no way to make chezmoi ignore some files in source directories like .chezmoiexternals/ or .chezmoitemplates, and this results in some annoyances when dealing with temporary and backup files from editors.

E.g., when vim .chezmoiexternals/chezmoi_modify_manager.toml is running:

$ chezmoi apply 
chezmoi: /home/vsu/.local/share/chezmoi/.chezmoiexternals/.chezmoi_modify_manager.toml.swp: not allowed in .chezmoiexternals directory

And after saving the file and exiting vim (so that the swap file with a problematic name is removed):

$ chezmoi apply 
chezmoi: /home/vsu/.local/share/chezmoi/.chezmoiexternals/chezmoi_modify_manager.toml~: .toml~: unknown format

I have **/*~ and **/.*.sw[a-p] in .chezmoiignore, but these patterns do not get applied to files which are used by chezmoi internally and not installed into the target directory.

Describe the solution you'd like

Ideally chezmoi should just use ignore patterns from .gitignore, but this is probably a too large request. Possible other options are:

  • .chezmoisrcignore with the same syntax as .chezmoiignore, but applied to all cases where files from the source directory are read.
  • ignoreSourcePatterns = ['**/*~', '**/.*.sw[a-p]'] in the configuration file.

Describe alternatives you've considered

It could be possible to avoid getting extra files written into the source directory, but there are some downsides:

  • The editor could be configured to disable backup files when editing files inside ~/.local/share/chezmoi. In this case the downsides are minor (especially given that the files should also be tracked in git).
  • Swap files could be disabled too, but in this case the downsides are more annoying, because in Vim swap files also function as lock files to prevent editing the same file in multiple Vim instances, therefore having the swap file in the same directory as the edited file is actually useful. And there is no support for the per-directory configuration of swap files in Vim.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions