Skip to content

Instantly share code, notes, and snippets.

Last active Nov 19, 2021
What would you like to do?
Chocolatey refreshenv for GIT Bash.
function refreshenv
powershell -NonInteractive - <<EOF
Write-Host("Updating environment session from chocolatey")
Import-Module "\$env:ChocolateyInstall\\helpers\\chocolateyProfile.psm1"
Write-Host("Scanning env")
# Round brackets in variable names cause problems with bash
\$results = Get-ChildItem env:* | %{
\$name = \$_.Name
if (!(\$name.Contains('(')) -And !(\$name.Contains('.'))) {
\$value = \$_.Value
if (\$name -eq 'PATH' -Or \$name -eq 'ORIGINAL_PATH') {
\$value = \$value -replace 'C:\\\\','/c/'
\$value = \$value -replace 'D:\\\\','/d/'
\$value = \$value -replace '\\\\','/'
\$value = \$value -replace ';',':'
if (\$name -eq 'PATH') {
\$hm = \$env:HOME
\$hm = \$hm -replace 'C:\\\\','/c/'
\$hm = \$hm -replace 'D:\\\\','/d/'
\$hm = \$hm -replace '\\\\','/'
\$hm = \$hm -replace ';',':'
\$value = "\$hm/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:\$value"
if ((\$name -ne 'HOME') -And \$name -ne 'SHELL' -And \$name -ne 'INFOPATH' -And \$name -ne 'MANPATH' -And \$name -ne 'PKG_CONFIG_PATH' -And \$name -ne 'PWD') {
Write-Output ("export \$name='\$value'")
# Write-Host("results = \$results")
\$results | Out-File -Encoding ascii \$filename
Write-Host("Wrote \$filename")
source "/c/temp/refresh.env"
if [[ -f ~/.bashrc ]]; then
source ~/.bashrc
alias RefreshEnv=refreshenv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment