Closed cglong closed 2 years ago
I actually just realized that, assuming I'm okay with my organization name being part of the source state, this can be accomplished using this method. Therefore, I guess this is more of a feature request 🙂
I don't quite understand what you want here. Is the suggestion that chezmoi should somehow automatically re-write directory names using registry keys?
No worries! Thank you for getting back to me 🙂
The suggestion would be for Chezmoi to detect shell folders (e.g. Documents
) and automatically sync them consistently across different systems. So C:\Users\chris\Documents
on one system and C:\Users\chris\OneDrive - {organization}\Documents
on another would receive the same target state.
Since opening this issue, I realized this is special-casing that may be considered out-of-scope, so I totally understand if this will be closed 🙂
Ah, thank you for the further details :)
I think you're on to something good here. I think there's potentially a much better way to handle the "handle different file locations on different systems with the same contents" problem whose FAQ entry you linked to.
Roughly it could look something like:
In your config file, you specify something like:
[rewriteTargetPaths]
"Documents" = "One Drive - {organization}/Documents"
This would tell chezmoi that whenever it finds Documents
in your source state it should replace it with One Drive - {organization}/Documents
in the target state.
To handle machine-to-machine differences, there's the existing config file generation mechanism which we can use. So, for example, your config file template would look something like:
[rewriteTargetPaths]
"Documents" = "One Drive - {{ registry "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Personal" }}"
(assuming the addition of a registry
template function to get values from the Windows registry)
For the use case of different directories in the FAQ entry, the config file template would look something like:
{{ if .chezmoi.os == "darwin" }}
# config file directory locations are different on macOS (darwin)
[rewriteTargetPaths]
".config/app" = "Library/Application Support/App"
{{ end }}
Implementing this has some subtleties (e.g. what should happen if multiple source directories are re-written to a single target directory) and will likely be non-trivial to implement, but you're definitely on to something here :)
Created #2273 to track this.
Describe the bug
My organization uses OneDrive PC folder backup to sync my Documents folder on Windows to OneDrive for Business. When I add a file in my Documents folder to Chezmoi, the path is
./OneDrive - {organization}/Documents
, which isn't compatible with non-work machines.To reproduce
New-Item $PROFILE
to ensure the file exists.chezmoi add $PROFILE
.Expected behavior
When the file is added to Chezmoi, it should just be at
./Documents
.Output of command with the
--verbose
flagNote that I've replaced my organization's name with
{organization}
for obfuscation purposes 🙂Output of
chezmoi doctor
Additional context
It appears there are a few ways to get the correct value of these folders:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Personal
[Environment]::GetFolderPath("MyDocuments")