-
Notifications
You must be signed in to change notification settings - Fork 502
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Set global flags using environment variables #2771
Comments
What at interesting feature request. It shouldn’t be hard to implement, although it would be necessary to make sure that the command-line parameters override the environment variables if both are specified. Can you describe how you would use multiple chezmoi repositories like this? I’d like to understand this use case a bit better to see if there’s a different feature that might be worth considering for a future release. |
Scenario4 different workstations, 3 different "users / usernames / home directories" (they're all me, private | work | work client). IssueToo much duplicated data (neomutt, ZSH, Neovim, GnuPG, TMUX, etc. etc.) Solution
Execution (order)
Practice
What would this fix ?
Having command-line parameters override environment variables would certainly be the standard way tools deal with order. Good catch |
Closes twpayne#2771 This provides an alternative to pure command-line flag configuration when working with multiple source trees.
I’ve added a draft PR that should work. There’s no tests, barely any documentation, and I haven’t even run it myself to see if it Does The Right Thing. I’ll get to that later, but I think that this should work. I’m sure you know this, but because I ran into this multiple times‡ myself recently (and I consider myself a direnv expert…), remember that direnv typically only updates on prompt display, so you would need to run In my case I was doing |
Thanks for the detailed info @lcrockett. A few questions/comments:
|
@twpayne, I’m not @lcrockett, but I can think of places where I might use this:
|
@halostatue |
Interesting, I implemented a system of my own to solve what you are proposing.
each of those work in a different context -
My different chezmoi based scripts use an environment variable named CONTEXT. I too use My scripts look like this:
paired with the following aliases:
As you can see the variation is in both A good example where the concept of CONTEXT comes into play is my
Or
I wrote I invoke it from command line like this:
The layered approach you are describing, will allow me to do this without all of the scripting infrastructure. |
Resolves twpayne#2771 When `$CHEZMOI_CONFIG` to be set, chezmoi will act as if it were called with `chezmoi --config $CHEZMOI_CONFIG`. If both `$CHEZMOI_CONFIG` and `--config PATH-TO-CONFIG` are provided, the command-line flag wins.
I just wrote in #2773 (comment):
|
Is your feature request related to a problem? Please describe.
When working with different chezmoi source directories on the same machine it is useful to be able to run a chezmoi command that is influenced by environment variables. For instance,
direnv
can be used to set different "cache | config | source" directory environment variables that chezmoi will use when executed.This allows one to cd to alternative source directories and being allowed to use
chezmoi diff
,chezmoi apply
, etc. while in the alternative directory and actually use that same source directory as a source path, and other alternative directories for the cache and configuration. This will prevent the necessity to always use--cache
|--config
|--source
with every invocation of chezmoi when using alternative directories.Describe the solution you'd like
Have chezmoi obey environment variables to influence the used cache | config | source directories. For instance
CHEZMOI_CACHE_PATH
|CHEZMOI_CONFIG_PATH
|CHEZMOI_SOURCE_PATH
.Describe alternatives you've considered
Alternatives are to add a local
.bin
directory to$PATH
with a script calledchezmoi
that executes chezmoi with the alternative directories set as arguments and then havedirenv
add that.bin
directory automatically upon entering a chezmoi source directory. Works, but using environment variables are more suited for this scenario and easier to maintain.The text was updated successfully, but these errors were encountered: