twpayne / chezmoi

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

`.chezmoi.destDir` empty on Windows #3496

Closed dpprdan closed 8 months ago

dpprdan commented 8 months ago

Describe the bug

According to the documentation, .chezmoi.destDir has the default value %USERPROFILE% in Windows. However, when I run chezmoi execute-template "{{ .chezmoi.destDir }}" I get an key has apparently not been set.

To reproduce

Steps to reproduce the behavior.

PS C:\> chezmoi execute-template "{{ .chezmoi.destDir }}"
chezmoi: template: arg1:1:11: executing "arg1" at <.chezmoi.destDir>: map has no entry for key "destDir"

Expected behavior

PS C:\> chezmoi execute-template "{{ .chezmoi.destDir }}"
C:/Users/Daniel

Output of command with the --verbose flag

PS C:\> chezmoi execute-template "{{ .chezmoi.destDir }}" --verbose
chezmoi: template: arg1:1:11: executing "arg1" at <.chezmoi.destDir>: map has no entry for key "destDir"

Output of chezmoi doctor

```ps1 PS C:\> chezmoi doctor RESULT CHECK MESSAGE ok version v2.45.0, commit 371703e93f0c54dad81f7cfbea2906ece15a7428, built at 2024-01-13T20:01:02Z, built by goreleaser ok latest-version v2.45.0 ok os-arch windows/amd64 ok systeminfo () ok go-version go1.21.6 (gc) ok executable C:/Program Files/WinGet/Links/chezmoi.exe ok upgrade-method winget-upgrade ok config-file ~/.config/chezmoi/chezmoi.toml, last modified 2024-01-19T16:26:32+01:00 warning source-dir ~/.local/share/chezmoi is a git working tree (dirty) ok suspicious-entries no suspicious entries warning working-tree ~/.local/share/chezmoi is a git working tree (dirty) ok dest-dir ~ is a directory ok cd-command found C:/WINDOWS/system32/cmd.exe ok cd-args 'C:\\WINDOWS\\system32\\cmd.exe' info diff-command not set ok edit-command found C:/Program Files/Microsoft VS Code/bin/code.cmd ok edit-args code --wait ok git-command found C:/Program Files/Git/cmd/git.exe, version 2.43.0 warning merge-command vimdiff not found in $PATH ok shell-command found C:/WINDOWS/system32/cmd.exe ok shell-args 'C:\\WINDOWS\\system32\\cmd.exe' info age-command age not found in $PATH info gpg-command gpg not found in $PATH 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 ```
dpprdan commented 8 months ago

I stumble over this while trying to include a public ssh key (something like ~/.ssh/id_rsa.pub) in a template. If there is a better way than {{ joinPath .chezmoi.destDir ".ssh/id_rsa.pub" | include | trim | quote }}, I am all ears (e.g. a way to expand a ~ path).

bradenhilton commented 8 months ago

This definitely seems like a bug.

Assuming you haven't overridden the destination directory, you can probably use .chezmoi.homeDir while we investigate.

dpprdan commented 8 months ago

Thanks for quick response! .chezmoi.homeDir is what I actually want.

This isn't a bug after all. Turns out I have been looking at the wrong document, i.e. configuration-file/variables instead of templates/variables. 🤦🏻‍♂️ Sorry for the confusion!!

Maybe there could/should be a chezmoi.destDir? But that is separate issue, so I am closing this.

Thanks again!