-
Notifications
You must be signed in to change notification settings - Fork 3
/
pipenv-shell.ps1
44 lines (40 loc) · 1.35 KB
/
pipenv-shell.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!powershell
#
# start this project's pipenv shell with decorated window title
$ErrorActionPreference = "Stop"
$DebugPreference = "Continue"
Set-PSDebug -Trace 2
Push-Location $PSScriptRoot
$title_original = $Host.UI.RawUI.WindowTitle
try {
if (-not (Get-Variable 'Python' -Scope 'Global' -ErrorAction 'Ignore')) {
if ([Environment]::GetEnvironmentVariable('Python'))
{
$Python = $env:Python
}
}
if (-not (Get-Variable 'Python' -Scope 'Global' -ErrorAction 'Ignore')) {
$Python = Get-Command -Name "python.exe"
}
# update the shell window title with information about the virtual environment
& $Python --version
if (-not $?) {
throw "ERROR: command failed: $Python --version"
}
$venv_loc = & $Python -m pipenv --venv
if (-not $?) {
throw "ERROR: command failed: $Python -m pipenv --venv"
}
$Host.UI.RawUI.WindowTitle = $Host.UI.RawUI.WindowTitle + "`npipenv: $venv_loc ($py_ver)"
# run `pipenv shell` command
Write-Debug "$Python -m pipenv shell`n"
& $Python -m pipenv shell $args
} finally {
Write-Debug "Exiting script $PSCommandPath"
Pop-Location
# restore the window title
$Host.UI.RawUI.WindowTitle = $title_original
# XXX: presuming these were the prior settings
$DebugPreference = "SilentlyContinue"
Set-PSDebug -Trace 0
}