Choco: RefreshEnv.sh

Created on 14 Jun 2019  Â·  7Comments  Â·  Source: chocolatey/choco

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

0 - _Triaging Enhancement

Most helpful comment

Any viable solution so far?

All 7 comments

Somewhat aside, there is a https://github.com/muntaserq/refreshenv for ruby processes, and https://github.com/saltstack/salt/issues/9876#issuecomment-488656118 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.

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.

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

Any viable solution so far?

Related to #1699

unsubcribe

El lun., 8 jun. 2020 a las 11:55, Rob Reynolds (notifications@github.com)
escribió:

Related to #1699 https://github.com/chocolatey/choco/issues/1699

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/chocolatey/choco/issues/1851#issuecomment-640680960,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AOSKSN4YBVBVAR2IY3OFFKLRVT3VPANCNFSM4HYEWNLQ
.

@solarisa I don't think that's how it works. There is a button on the github page that will allow you to do what you want. HTH

Was this page helpful?
0 / 5 - 0 ratings