Skip to content

Instantly share code, notes, and snippets.

@zimbatm
Created November 25, 2018 20:03
Show Gist options
  • Save zimbatm/ee97a194d77f162550b0347890eff120 to your computer and use it in GitHub Desktop.
Save zimbatm/ee97a194d77f162550b0347890eff120 to your computer and use it in GitHub Desktop.
# Install with:
#
# new-item -itemtype file -path $profile -force
# cp direnv.ps1 $profile
#
# # maybe
# Set-ExecutionPolicy RemoteSigned
#
#
# Run before the prompt
function direnvHook {
$diff = & direnv export json | ConvertFrom-Json
# No output, return
if (!$diff) {
return
}
# Apply the diff
$diff.psobject.properties | ForEach {
$o = $_
if ($o.Value -Or $o.Value -eq "") {
#Write-Output "Setting $($o.Name) to $($o.Value)"
Set-Item -path "Env:$($o.Name)" -value $o.Value
} else {
#Write-Output "Deleting $($o.Name)"
Remove-Item -path "Env:$($o.Name)"
}
}
}
function Global:prompt {
# Add this before showing the prompt
direnvHook
return "PS $PWD> "
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment