twpayne / chezmoi

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

Chezmoi init works on Windows but not in Linux #3942

Closed MRDGH2821 closed 2 months ago

MRDGH2821 commented 2 months ago

What exactly are you trying to do?

Trying to initialise my dotfiles

What have you tried so far?

Checked indentation of toml template, it is valid. Checked toml templates of other users, used their indentation settings, still does not work.

Where else have you checked for solutions?

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

$ chezmoi --verbose init
chezmoi: /home/mihirr/.local/share/chezmoi/.chezmoi.toml.tmpl: toml: expected newline but got U+0063 'c'

Output of chezmoi doctor

```console $ chezmoi doctor ``` ```log fatal: not a git repository (or any of the parent directories): .git RESULT CHECK MESSAGE ok version v2.52.2, commit f91dbfc2256b59c003ecdf28815a265e48eeecc3, built at 2024-09-10T00:13:37Z, built by goreleaser ok latest-version v2.52.2 ok os-arch linux/amd64 (KDE neon 6.0) ok uname Linux mr-starlite 6.8.0-40-generic #40~22.04.3-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 30 17:30:19 UTC 2 x86_64 x86_64 x86_64 GNU/Linux ok go-version go1.23.1 (gc) ok executable /usr/bin/chezmoi ok upgrade-method sudo-upgrade-package ok config-file no config file found ok source-dir ~/.local/share/chezmoi is a git working tree (clean) ok suspicious-entries no suspicious entries ok working-tree ~/.local/share/chezmoi is a git working tree (clean) error dest-dir ~ is a git working tree (error) ok umask 002 ok cd-command found /bin/bash ok cd-args /bin/bash info diff-command not set ok edit-command found /usr/bin/vi ok edit-args /usr/bin/vi ok git-command found /usr/bin/git, version 2.34.1 ok merge-command found /usr/bin/vimdiff ok shell-command found /bin/bash ok shell-args /bin/bash info age-command age not found in $PATH ok gpg-command found /usr/bin/gpg, version 2.2.27 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 ok keepassxc-command found /usr/bin/keepassxc-cli, version 2.7.9 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 ``` After renaming `~/.git` -> `~/.git.bkp`: ```log RESULT CHECK MESSAGE ok version v2.52.2, commit f91dbfc2256b59c003ecdf28815a265e48eeecc3, built at 2024-09-10T00:13:37Z, built by goreleaser ok latest-version v2.52.2 ok os-arch linux/amd64 (KDE neon 6.0) ok uname Linux mr-starlite 6.8.0-40-generic #40~22.04.3-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 30 17:30:19 UTC 2 x86_64 x86_64 x86_64 GNU/Linux ok go-version go1.23.1 (gc) ok executable /usr/bin/chezmoi ok upgrade-method sudo-upgrade-package ok config-file no config file found ok source-dir ~/.local/share/chezmoi is a git working tree (clean) ok suspicious-entries no suspicious entries ok working-tree ~/.local/share/chezmoi is a git working tree (clean) ok dest-dir ~ is a directory ok umask 002 ok cd-command found /bin/bash ok cd-args /bin/bash info diff-command not set ok edit-command found /usr/bin/vi ok edit-args /usr/bin/vi ok git-command found /usr/bin/git, version 2.34.1 ok merge-command found /usr/bin/vimdiff ok shell-command found /bin/bash ok shell-args /bin/bash info age-command age not found in $PATH ok gpg-command found /usr/bin/gpg, version 2.2.27 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 ok keepassxc-command found /usr/bin/keepassxc-cli, version 2.7.9 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 ``` Still doesn't work

Additional context

$ fastfetch
mihirr@mr-starlite
------------------
OS: KDE neon jammy 22.04 x86_64
Host: StarLite (1.0)
Kernel: Linux 6.8.0-40-generic
Uptime: 48 mins
Shell: bash 5.1.16
Display (LG ULTRAGEAR): 2560x1440 @ 144 Hz in 27″ [External]
Display (BOE0B36): 2160x1440 @ 60 Hz (as 1440x960) in 13″ [Built-in] *
DE: KDE Plasma 6.1.5
WM: KWin (Wayland)
Terminal: konsole 24.8.0
CPU: Intel(R) N200 (4) @ 3.70 GHz
GPU: Intel Device 46D0 (VGA compatible) @ 0.75 GHz [Integrated]
Memory: 8.36 GiB / 15.47 GiB (54%)
Swap: 0 B / 512.00 MiB (0%)
Disk (/): 78.48 GiB / 468.09 GiB (17%) - ext4
Disk (/media/mihirr/1tb-sandisk): 381.00 GiB / 953.49 GiB (40%) - btrfs
BIOS Version: 24.08
Firmware Version: 24.8

Visit StarLite MK V page: https://starlabs.systems/pages/starlite
bradenhilton commented 2 months ago

This is an issue with the whitespace control characters:

As is, on Windows:

❯ Get-Content .\3942.toml.tmpl | chezmoi execute-template --init
[data]
email = "Email address"
username = "MRDGH2821"
profile = "personal"

[edit]
command = "Editor (code/zed)"
args = ["--wait"]

[keepassxc]
database = "KeepassXC DB Path"

encryption = "gpg"
[gpg]
recipient = "D30D1B600CF5CDEE9EC2D7DBDAD1E1E272A1FA73"

[hooks.read-source-state.pre]
command = "powershell"
args = [".local/share/chezmoi/.chezmoiscripts/.install-password-manager.ps1"]

If I change the if to {{- if eq .chezmoi.os "linux" }} (while still on Windows):

❯ Get-Content .\3942.toml.tmpl | chezmoi execute-template --init
[data]
email = "Email address"
username = "MRDGH2821"
profile = "personal"

[edit]
command = "Editor (code/zed)"
args = ["--wait"]

[keepassxc]
database = "KeepassXC DB Path"

encryption = "gpg"
[gpg]
recipient = "D30D1B600CF5CDEE9EC2D7DBDAD1E1E272A1FA73"

[hooks.read-source-state.pre]command = ".local/share/chezmoi/.chezmoiscripts/.install-password-manager.sh"

In this situation, I would recommend

{{ if ... -}}
...
{{- else -}}
...
{{- end }}

or just removing them.

MRDGH2821 commented 2 months ago

Thank you very much! That works as expected