twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
13.51k stars 494 forks source link

msys2 not detected, bash scripts will run with windows shell #3904

Closed srouquette closed 3 months ago

srouquette commented 3 months ago

What exactly are you trying to do?

my repo, I will change it's name later.
I'm trying to have a single dotfiles repo, which will work on Windows, msys2 and linux (wsl).
I installed chezmoi via scoop (windows) and it's also available on msys2. My setup on Windows works. Now, when I try to run chezmoi on msys2 with bash scripts, it produces an error like it's trying to run them as Windows scripts I also symlinked ~/.local/share/chezmoi to /c/Users/syl/.local/share/chezmoi to have a single repo.

Here is the output on msys2:

chezmoi apply
chezmoi: .chezmoiscripts/msys2/00-install-packages.sh: fork/exec C:\Users\Syl\AppData\Local\Temp\3757994991.00-install-packages.sh: %1 is not a valid Win32 application.

What have you tried so far?

Describe what you have tried so far.

Where else have you checked for solutions?

Output of any commands you've tried with --verbose flag

$ chezmoi --verbose apply
C:/Users/Syl/AppData/Local/Temp/chezmoi-diff2851475333/.chezmoiscripts/msys2/00-install-packages.sh --- Bash
 1 #!/usr/bin/env bash
 2 set -eufo pipefail
 3
 4 pacman_packages=(
 5     pactoys
 6     openssh
 7     unzip
 8     zsh
 9 )
10 pactoys_packages=(
11     delta:p
12     fzf:p
13     helix:p
14     micro:p
15     python-tldr:p
16     starship:p
17     vivid:p
18 )
19
20 for package in "${pacman_packages[@]}"; do
21   if ! pacman -Q "$pkg" &>/dev/null; then
22     echo echo pacman -S --noconfirm "$pkg"
23   fi
24 done
25
26 for package in "${pactoys_packages[@]}"; do
27   if ! pacboy -Q "$pkg" &>/dev/null; then
28     echo pacboy -S --noconfirm "$pkg"
29   fi
30 done
31

chezmoi: .chezmoiscripts/msys2/00-install-packages.sh: fork/exec C:\Users\Syl\AppData\Local\Temp\888354414.00-install-packages.sh: %1 is not a valid Win32 application.

Output of chezmoi doctor

```console $ chezmoi doctor RESULT CHECK MESSAGE ok version v2.52.0, commit 64f40d93ea1f1456a6788798b9e9c4813156d86e, built at 2024-08-07T21:09:57Z, built by goreleaser ok latest-version v2.52.0 ok os-arch windows/amd64 ok systeminfo () ok go-version go1.22.6 (gc) ok executable C:/Users/Syl/scoop/apps/chezmoi/current/chezmoi.exe ok config-file ~/.config/chezmoi/chezmoi.toml, last modified 2024-08-15T07:12:32+02:00 ok source-dir ~/.local/share/chezmoi is a git working tree (clean) warning suspicious-entries ~/.local/share/chezmoi/._/chezmoi.json ok working-tree ~/.local/share/chezmoi is a git working tree (clean) ok dest-dir ~ is a directory ok cd-command found C:/msys64/usr/bin/zsh.exe ok cd-args 'C:\\msys64\\usr\\bin\\zsh.exe' ok diff-command found C:/Users/Syl/scoop/shims/difft.exe ok edit-command found C:/Users/Syl/scoop/apps/vscode/current/bin/code.cmd ok edit-args code --wait ok git-command found C:/msys64/mingw64/bin/git.exe, version 2.46.0 ok merge-command found C:/Users/Syl/scoop/shims/meld.exe ok shell-command found C:/msys64/usr/bin/zsh.exe ok shell-args 'C:\\msys64\\usr\\bin\\zsh.exe' info age-command age not found in $PATH ok gpg-command found C:/msys64/usr/bin/gpg.exe, version 2.4.5 info pinentry-command not set info 1password-command op not found in $PATH info bitwarden-command bw not found in $PATH info bitwarden-secrets-command bws not found in $PATH info dashlane-command dcli not found in $PATH info doppler-command doppler not found in $PATH info gopass-command gopass not found in $PATH info keepassxc-command keepassxc-cli not found in $PATH info keepassxc-db not set info keeper-command keeper not found in $PATH info lastpass-command lpass not found in $PATH info pass-command pass not found in $PATH info passhole-command ph not found in $PATH info rbw-command rbw not found in $PATH info vault-command vault not found in $PATH info vlt-command vlt not found in $PATH info secret-command not set ```

Additional context

I also noticed that when I made a mistake in a command in go template, for example {{- $vscode_ext := output "code --list-extensions" -}}, it seemed to look in %PATH% instead of $PATH.

chezmoi: .chezmoiscripts/configure-vscode.ps1: template: .chezmoiscripts/run_onchange_after_configure-vscode.ps1.tmpl:25:19: executing ".chezmoiscripts/run_onchange_after_configure-vscode.ps1.tmpl" at <output "code --list-extensions">: error calling output: 'code --list-extensions': exec: "code --list-extensions": executable file not found in %PATH%

Also, the code above is a bit of a trick, the extension is .ps1, but I have this in .chezmoi.toml

{{ if ne $os "windows" -}}
[interpreters.ps1]
    command = "bash"
{{- end }}
srouquette commented 3 months ago

as a work around, forcing the interpreter (like for .ps1) seems to work.

{{ if ne $os "windows" -}}
[interpreters.sh]
    command = "bash"
[interpreters.ps1]
    command = "bash"
{{- end }}
twpayne commented 3 months ago

as a work around, forcing the interpreter (like for .ps1) seems to work.

Setting interpreters.sh is the correct solution, not a workaround.