Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RefreshEnv.sh #1851

Open
jayvdb opened this issue Jun 14, 2019 · 7 comments
Open

RefreshEnv.sh #1851

jayvdb opened this issue Jun 14, 2019 · 7 comments

Comments

@jayvdb
Copy link

jayvdb commented Jun 14, 2019

choco is provided as part of the Travis CI Windows environment https://docs.travis-ci.com/user/reference/windows/ , and SHELL=/usr/bin/bash, and uname -a is MSYS_NT-10.0 2.10.0(0.325/5/3) 2018-07-25 13:06 x86_64 Msys, and comes from choco package git.install which is https://gitforwindows.org/.

A solution similar to RefreshEnv.cmd is needed for the shell. i.e. the user would need to do source refreshenv.sh , and maybe an alias could be created so that refreshenv is source refreshenv.sh

@jayvdb
Copy link
Author

jayvdb commented Jun 14, 2019

Somewhat aside, there is a https://github.com/muntaserq/refreshenv for ruby processes, and saltstack/salt#9876 (comment) looks like it doesnt need much alteration to be a refreshenv for any python process. Probably would be useful to have implementations for various runtimes available as choco packages.

@jayvdb
Copy link
Author

jayvdb commented Jun 16, 2019

I have a half reasonable solution piggy-backing on Update-SessionEnvironment since it already does a lot of the work needing to be done.

gen_refreshenv.ps1

Import-Module C:\ProgramData\chocolatey\helpers\chocolateyProfile.psm1

Update-SessionEnvironment

# Round brackets in variable names cause problems with bash
# msys bash requires ':' instead of ';' for PATH, PWD, OLDPWD and a few others.
Get-ChildItem env:* | %{
  if (!($_.Name.Contains('('))) {
    $value = $_.Value
    if ($_.Name -eq 'PATH') {
      $value = $value -replace ';',':'
    }
    Write-Output ("export " + $_.Name + "='" + $value + "'")
  }
} | Out-File -Encoding ascii C:\TEMP\refreshenv.sh

Then source /c/TEMP/refreshenv.sh .

Obviously not polished as it needs unique filenames for the temp file, and needs to be all done in a bash function with as few extra dependencies as possible. Also need to change the encoding, and test it with environment variable names and values which contain unicode, to determine what are the limitations there. Just using -encoding utf8 fails badly on my CI worker - probably needs LANG set, etc.

Ideally the logic in the above script could be put into a helper like Write-Environment which can emit the environment in various formats, not just msys bash, and probably the ps1 helper also needs to know what encoding it should use, and then it would skip rows which would cause failures. I assume that other shells will have slightly different needs, and iirc cygwin cant handle C:\.. in the PATH so those need to be converted with cygpath.

@jayvdb
Copy link
Author

jayvdb commented Jun 17, 2019

https://gist.github.com/jayvdb/1daf8c60e20d64024f51ec333f5ce806 - unicode is replaced with ?, but otherwise works reasonably well on the travis win32 worker.

@lamba92
Copy link

lamba92 commented Nov 6, 2019

Any viable solution so far?

@ferventcoder
Copy link
Member

Related to #1699

@solarisa

This comment has been minimized.

@ferventcoder

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants