Skip to content

Instantly share code, notes, and snippets.

@tats-u
Last active April 10, 2019 08:43
Show Gist options
  • Save tats-u/5de00598808843ad6ec0420055683bbc to your computer and use it in GitHub Desktop.
Save tats-u/5de00598808843ad6ec0420055683bbc to your computer and use it in GitHub Desktop.
Enable `conda (de)activate` in PowerShell
function conda($cmd) {
# ↓ Change me
$scripts_root = "C:\tools\Anaconda3\Scripts"
function Add-ScriptsRootIfNeeded($exe) {
$ret = if (Get-Command $exe -ErrorAction Ignore) {
$exe
}
else {
Join-Path $scripts_root $exe
}
return $ret
}
switch -Exact ($cmd) {
"activate" {
& (Add-ScriptsRootIfNeeded "activate.ps1") @args
break
}
"deactivate" {
& (Add-ScriptsRootIfNeeded "deactivate.ps1") @args
break
}
default {
$all_args = if ($null -ne $cmd) { @($cmd) + $args } else { @() }
& (Add-ScriptsRootIfNeeded "conda.exe") @all_args
break
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment