Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Install latest direnv from github releases with powershell
Downloads and installs most recent direnv cli app to your user profile.
Default location will be $HOME/.local/bin (which is also added to your environment path)
Function Update-SystemPath {
$VerifiedPathsToAdd = $Null
Foreach ($Path in $PathToAdd) {
if ($env:Path -like "*$Path*") {
Write-Output "Currnet item in path is: $Path"
Write-Output "$Path already exists in Path statement"
else {
$VerifiedPathsToAdd += ";$Path"
Write-Output "`$VerifiedPathsToAdd updated to contain: $Path"
if ($null -ne $VerifiedPathsToAdd) {
Write-Output "`$VerifiedPathsToAdd contains: $verifiedPathsToAdd"
Write-Output "Adding $Path to Path statement now..."
[Environment]::SetEnvironmentVariable("Path", $env:Path + $VerifiedPathsToAdd, "Process")
Update-SystemPath "$HOME\.local\bin"
# Download latest direnv/direnv release from github
$repo = "direnv/direnv"
$file = ""
$filepath = "$HOME\.local\bin"
$outfile = Join-Path $filepath 'direnv.exe'
$releases = "$repo/releases"
Write-Output "Determining latest release of $file"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$tag = (Invoke-WebRequest -Uri $releases -UseBasicParsing | ConvertFrom-Json)[0].tag_name
Write-Output "Tag retrieved: $tag"
$download = "$repo/releases/download/$tag/$file"
$name = $file.Split(".")[0]
Write-Output "Download URL: $download"
Write-Output "File Name: $name"
Write-Output "Downloading to $name"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest $download -Out $name
Remove-Item $outfile -Force -ErrorAction:SilentlyContinue
Move-Item $name $outfile
Write-Output "Installed to $outfile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.