*.plist files broke chezmostatus and diff
Closed this issue · 4 comments
Describe the bug
When saving *.plist files with chezmoi add
and then checking the status with chezmoi status
, chezmoi will say the files aren't the same (without any differences).
To reproduce
Step 1)
$ chezmoi add Library/Preferences/com.googlecode.iterm2.plist
Step 2)
$ chezmoi status
MM Library/Preferences/com.googlecode.iterm2.plist
Expected behavior
In the step 2 we should have no differences returned by chezmoi status
nor chezmoi diff
Output of command with the --verbose
flag
$ chezmoi --verbose status
MM Library/Preferences/com.googlecode.iterm2.plist
Output of chezmoi doctor
$ chezmoi doctor
RESULT CHECK MESSAGE
ok version v2.47.1, commit 1ce6b2eeb0caf75bd91883e5a968e713a26e7be2, built at 2024-03-03T00:47:52Z, built by Homebrew
ok latest-version v2.47.1
ok os-arch darwin/arm64
ok uname Darwin MACM-DWKDW2L4WM 23.3.0 Darwin Kernel Version 23.3.0: Wed Dec 20 21:30:44 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6000 arm64
ok go-version go1.22.0 (gc)
ok executable /opt/homebrew/bin/chezmoi
ok upgrade-method brew-upgrade
ok config-file ~/.config/chezmoi/chezmoi.yaml, last modified 2024-03-14T16:23:31+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 umask 022
ok cd-command found /bin/zsh
ok cd-args /bin/zsh
ok diff-command found /opt/homebrew/bin/code
ok edit-command found /opt/homebrew/bin/code
ok edit-args code --wait
ok git-command found /opt/homebrew/bin/git, version 2.44.0
ok merge-command found /opt/homebrew/bin/code
ok shell-command found /bin/zsh
ok shell-args /bin/zsh
info age-command age not found in $PATH
ok gpg-command found /opt/homebrew/bin/gpg, version 2.4.5
info pinentry-command not set
ok 1password-command found /opt/homebrew/bin/op, version 2.25.0
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
Note that I tried to chezmoi re-add
, chezmoi apply
and then overwrite, but chezmoi status
keep saying that there are differences between the files.
Thanks a lot for all your work on chezmoi.
$ chezmoi status MM Library/Preferences/com.googlecode.iterm2.plist
The M
in the first column indicates that another program (probably iTerm2 itself) has modified Library/Preferences/com.googlecode.iterm2.plist
since chezmoi last wrote it. Therefore, if chezmoi were to overwrite it, then you would lose some local changes.
Unfortunately iTerm2 is one of those naughty programs that modifies its own configuration files. You have a few options:
- Use a
modify_
script to just modify the parts ofcom.googlecode.iterm2.plist
that you care about. - Or, use this symlink technique.
- Or, use a script that uses macOS's
defaults
command.
Thanks a lot for your reply!
You're right, the issue is on ITerm2 side.
I tried your options:
- modify_ script is not a suitable solution because the
*.plist
files are binary files, so I can't really know which part to modify with chezmoi. - this symlink technique is not possible anymore on MacOS 14 (symlinks can't be used in
Library/Preferences
anymore). That's why I wanted to use the copy mechanism in the first place. - macOS's defaults command can't help me save my ITerm2 configuration, unfortunately.
I can't think of another alternative to bypass this new MacOS 14 limitation & my need to save some app's configuration. Maybe I will just chezmoi apply --force
and if I need to persist some new settings, I will need to chezmoi re-add
🤔
Anyway, thanks for everything @twpayne 🙏
- modify_ script is not a suitable solution because the
*.plist
files are binary files, so I can't really know which part to modify with chezmoi.
I think something like the following should work in ~/.local/share/chezmoi/Library/Preferences/modify_com.googlecode.iterm2.plist
(warning: untested):
#!/bin/bash
# create a temporary file
tmpfile=$(mktemp)
# ensure that the temporary file is removed on exit
trap "rm -f $(tmpfile)" EXIT
# write the .plist to the temporary file
cat > "$(tmpfile)"
# replace .plist values in the temporary file
plutil -replace MyBoolValue -bool false "$(tmpfile)"
# write the temporary file to stdout
cat "$(tmpfile)"
- macOS's defaults command can't help me save my ITerm2 configuration, unfortunately.
I think you can use a script that uses plutil
to replace values in Library/Preferences/com.googlecode.iterm2.plist
(warning: untested).
Interesting! It's gonna need a bit of digging, but I'm going to try that out! Thanks a lot for your ideas!