# Cool Computers CLI installation

> Install the official native Cool Computers CLI directly.

## macOS and Linux

```sh
curl -fsSL https://cool.computer/install.sh | sh
```

## Windows PowerShell

```powershell
(iwr -UseBasicParsing https://cool.computer/install.ps1).Content | iex
```

The installer adds `cool` to the current PowerShell session and your user
`PATH`. Restart terminal apps that were already open before installation.

## Update and remove

Run the installer again to update:

```sh
curl -fsSL https://cool.computer/install.sh | sh
```

Remove the macOS or Linux CLI:

```sh
rm ~/.local/bin/cool
```

Remove the Windows CLI:

```powershell
$installDir = "$env:LOCALAPPDATA\Programs\coolcomputer"
$executable = "$installDir\cool.exe"
if (Test-Path -LiteralPath $executable) {
  Remove-Item -LiteralPath $executable -ErrorAction Stop
}
$pathChanged = $false
$environmentKey = [Microsoft.Win32.Registry]::CurrentUser.CreateSubKey("Environment")
if ($null -eq $environmentKey) {
  throw "cool could not open the user environment registry key"
}
try {
  if ($environmentKey.GetValueNames() -contains "Path") {
    $pathKind = $environmentKey.GetValueKind("Path")
    if ($pathKind -ne [Microsoft.Win32.RegistryValueKind]::String -and $pathKind -ne [Microsoft.Win32.RegistryValueKind]::ExpandString) {
      throw "the user PATH registry value is not a string"
    }
    $userPath = [string]$environmentKey.GetValue("Path", "", [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames)
    $pathEntries = @($userPath -split ";")
    $newPathEntries = @($pathEntries | Where-Object {
      $entry = if ($pathKind -eq [Microsoft.Win32.RegistryValueKind]::ExpandString) {
        [Environment]::ExpandEnvironmentVariables($_)
      } else {
        $_
      }
      $entry -ne $installDir
    })
    if ($newPathEntries.Count -ne $pathEntries.Count) {
      $newPath = $newPathEntries -join ";"
      if ($newPath) {
        $environmentKey.SetValue("Path", $newPath, $pathKind)
      } else {
        $environmentKey.DeleteValue("Path")
      }
      $pathChanged = $true
    }
  }
} finally {
  $environmentKey.Dispose()
}
$env:Path = (($env:Path -split ";" | Where-Object { $_ -ne $installDir }) -join ";")
if ($pathChanged) {
  try {
    if (-not ("CoolComputer.NativeEnvironment" -as [type])) {
      Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
namespace CoolComputer {
  public static class NativeEnvironment {
    [DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
    public static extern IntPtr SendMessageTimeout(IntPtr window, uint message, UIntPtr wparam, string lparam, uint flags, uint timeout, out UIntPtr result);
  }
}
"@
    }
    $result = [UIntPtr]::Zero
    $published = [CoolComputer.NativeEnvironment]::SendMessageTimeout([IntPtr]0xffff, 0x001a, [UIntPtr]::Zero, "Environment", 0x0002, 5000, [ref]$result)
    if ($published -eq [IntPtr]::Zero) {
      Write-Warning "cool was removed from your user PATH, but Windows did not notify running apps. Restart them to reload PATH."
    }
  } catch {
    Write-Warning "cool was removed from your user PATH, but Windows could not notify running apps: $_"
  }
}
```
