Code Monkey home page Code Monkey logo

Comments (2)

bradenhilton avatar bradenhilton commented on June 2, 2024

The subdirectory is part of the target path/name. If it wasn't, you could easily run into collisions with identically named files in separate directories. .chezmoiscripts entries still have a target path despite no file in the destination state being created.

From https://www.chezmoi.io/reference/application-order:

  1. Run run_before_ scripts in alphabetical order.
  2. Update entries in the target state (files, directories, externals, scripts, symlinks, etc.) in alphabetical order of their target name. Directories (including those created by externals) are updated before the files they contain.
  3. Run run_after_ scripts in alphabetical order.

Target names are considered after all attributes are stripped.

chezmoi\homeGet-ChildItem -File -Path @('.\.chezmoiscripts\global\', '.\.chezmoiscripts\darwin\', '.\.chezmoiscripts\linux\') | ForEach-Object { [System.IO.Path]::GetRelativePath((chezmoi target-path), (chezmoi target-path $_)) } | Sort-Object
.chezmoiscripts\darwin\10_setup-install-homebrew.sh
.chezmoiscripts\darwin\20_setup-brew-packages.sh
.chezmoiscripts\global\00_bootstrap_decrypt-age-key.sh

(Note how I deliberately accumulated the source directories in a non-alphabetical order and then finally sorted the target paths relative to the destination directory)

If the script really is global as you mention, consider moving it outside of the subdirectory i.e. .chezmoiscripts/run_before_00_bootstrap_decrypt-age-key.sh.tmpl:

chezmoi\homeGet-ChildItem -File -Path @('.\.chezmoiscripts\darwin\', '.\.chezmoiscripts\linux\', '.\.chezmoiscripts\') | ForEach-Object { [System.IO.Path]::GetRelativePath((chezmoi target-path), (chezmoi target-path $_)) } | Sort-Object
.chezmoiscripts\00_bootstrap_decrypt-age-key.sh
.chezmoiscripts\darwin\10_setup-install-homebrew.sh
.chezmoiscripts\darwin\20_setup-brew-packages.sh

(Again, note the deliberate incorrect order in which I generate the target paths, before sorting them)

from chezmoi.

arrrgi avatar arrrgi commented on June 2, 2024

Thanks for the clear and excellent explanation @bradenhilton

Target names are considered after all attributes are stripped.

This was the lightbulb moment in the documentation for me.

from chezmoi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.