starship icon indicating copy to clipboard operation
starship copied to clipboard

feat: allow loading configuration values from the environment

Open davidkna opened this issue 2 years ago • 6 comments

Description

This PR allows overwriting individual config keys with config keys like STARSHIP_CONFIG__STATUS__DISABLED=false. The code is very similar to the starship config sub-command. This allows making smaller overrides to the configuration without needing to create duplicate config files. ~~toml_edit is used for parsing the values, because toml does not support this, but it looks like both toml and toml_edit will use the same value types soon.~~ toml is used for parsing values now.

Motivation and Context

Related #4352 Closes #4808

Screenshots (if appropriate):

How Has This Been Tested?

  • [x] I have tested using MacOS
  • [ ] I have tested using Linux
  • [ ] I have tested using Windows

Checklist:

  • [x] I have updated the documentation accordingly.
  • [x] I have updated the tests accordingly.

davidkna avatar Oct 03 '22 13:10 davidkna

Hi!

I'm the initiator of #4352.

I'm in favour of this PR, but I'm not sure if it should really close 4352, since the feature includes other content that was not implemented in this PR.

Tested this PR:

$ starship timings
 Here are the timings of modules in your prompt (>=1ms or output):
 git_commit   -  1281ms  -   ""
 directory    -  1156ms  -   "«:gvfs/smb-share:domain=xxx,server=yyy,share=releases,user=sfr/zzz "
 git_state    -  1142ms  -   ""
 git_status   -  1141ms  -   ""
 git_metrics  -  1128ms  -   ""
 git_branch   -   751ms  -   ""
 pulumi       -   603ms  -   ""
 hg_branch    -   451ms  -   ""
 battery      -     1ms  -   ""
 character    -    <1ms  -   "➜  "

$ STARSHIP_CONFIG__GIT_COMMIT__DISABLED=true STARSHIP_CONFIG__GIT_STATE__DISABLED=true STARSHIP_CONFIG__GIT_METRICS__DISABLED=true STARSHIP_CONFIG__GIT_STATUS__DISABLED=true STARSHIP_CONFIG__GIT_BRANCH__DISABLED=true starship timings
 Here are the timings of modules in your prompt (>=1ms or output):
 directory    -  1152ms  -   "«:gvfs/smb-share:domain=xxx,server=yyy,share=releases,user=sfr/zzz "
 pulumi       -   616ms  -   ""
 hg_branch    -   128ms  -   ""
 battery      -     1ms  -   ""
 character    -    <1ms  -   "➜  "

Thanks for your work!

silvio avatar Oct 04 '22 15:10 silvio

What's the status of this PR? I ran across it because I need a way to disable specific modules when using one shell vs. others and environment variables would perfectly solve my problem (because I can check for the shell and set appropriate environment variables in .bashrc just prior to loading Starship). If there's something I could do to help contribute to moving it toward being available to end users, I'd love to do so.

onecrayon avatar Feb 25 '23 00:02 onecrayon

I would also love to see this land: I use direnv for setting up env vars per folder/projects and enabling the kubernetes module only in folders which need it would be really nice, especially together with kubesess which can automatically set the right namespace/context per terminal session.

So: any help needed? I would love to help getting this over the finish line...

jankatins avatar Oct 25 '23 19:10 jankatins

Is this stagnated, or still being worked on? Just hit a case today where this would be very helpful. Anything I can do to assist?

badloop avatar Feb 14 '24 14:02 badloop

Yay! It does exactly what I suggested. Great! ❤️ I have tested the following:

«:starship on  feso/test is 📦 v1.17.1 via 🦀 v1.74.0 ➜  starship timings
                                                                  
 Here are the timings of modules in your prompt (>=1ms or output):
 git_status   -  12ms  -   ""                                     
 git_metrics  -  10ms  -   ""                                     
 rust         -   9ms  -   "via 🦀 v1.74.0 "                      
 directory    -  <1ms  -   "«:starship "                          
 git_branch   -  <1ms  -   "on  feso/test "                      
 package      -  <1ms  -   "is 📦 v1.17.1 "                       
 character    -  <1ms  -   "➜  "                                  


«:starship on  feso/test is 📦 v1.17.1 via 🦀 v1.74.0 ➜  export STARSHIP__RUST__DISABLE=true
«:starship on  feso/test is 📦 v1.17.1 via 🦀 v1.74.0 ➜  export STARSHIP_CONFIG__RUST__DISABLED=true
«:starship on  feso/test is 📦 v1.17.1 ➜  export STARSHIP_CONFIG__GIT_METRICS__DISABLED=true
«:starship on  feso/test is 📦 v1.17.1 ➜  export STARSHIP_CONFIG__GIT_STATUS__DISABLED=true
«:starship on  feso/test is 📦 v1.17.1 ➜  export STARSHIP_CONFIG__GIT_BRANCH__TRUNCATION_LENGTH=4
«:starship on  feso… is 📦 v1.17.1 ➜  export STARSHIP_CONFIG__GIT_BRANCH__SYMBOL='xxx '
«:starship on xxx feso… is 📦 v1.17.1 ➜  starship timings

 Here are the timings of modules in your prompt (>=1ms or output):
 battery     -   9ms  -   ""
 directory   -  <1ms  -   "«:starship "
 git_branch  -  <1ms  -   "on xxx feso… "
 package     -  <1ms  -   "is 📦 v1.17.1 "
 character   -  <1ms  -   "➜  "

Perfect!

silvio avatar Feb 15 '24 07:02 silvio

Seeing how both above-mentioned PRs got merged, please consider merging this PR as well. I've been using this patch since February 15 with my config, and am using it to change the color scheme on the fly.

nekowinston avatar Apr 10 '24 19:04 nekowinston