-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowershell
69 lines (55 loc) · 1.9 KB
/
powershell
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# DIYship {{{
$ENV:VIRTUAL_ENV_DISABLE_PROMPT = 1
$ENV:DIYSHIP_SHELL = "powershell"
function global:prompt {
function Invoke-Native {
param($Executable, $Arguments)
$startInfo = [System.Diagnostics.ProcessStartInfo]::new($Executable);
$startInfo.StandardOutputEncoding = [System.Text.Encoding]::UTF8;
$startInfo.RedirectStandardOutput = $true;
$startInfo.RedirectStandardError = $true;
$startInfo.CreateNoWindow = $true;
$startInfo.UseShellExecute = $false;
if ($startInfo.ArgumentList.Add) {
foreach ($arg in $Arguments) {
$startInfo.ArgumentList.Add($arg);
}
}
else {
$escaped = $Arguments | ForEach-Object {
$s = $_ -Replace '(\+)"','$1$1"';
$s = $s -Replace '(\+)$','$1$1';
$s = $s -Replace '"','\"';
"`"$s`""
}
$startInfo.Arguments = $escaped -Join ' ';
}
$process = [System.Diagnostics.Process]::Start($startInfo)
$stderr = $process.StandardError.ReadToEnd().Trim()
if ($stderr -ne '') {
$host.ui.WriteErrorLine($stderr)
}
$process.StandardOutput.ReadToEnd();
}
$origDollarQuestion = $global:?
$origLastExitCode = $global:LASTEXITCODE
$ENV:DIYSHIP_JOBS = @(Get-Job | Where-Object { $_.State -eq 'Running' }).Count
$ENV:DIYSHIP_STATUS = 0
if ($lastCmd = Get-History -Count 1) {
if (-not $origDollarQuestion) {
$lastCmdletError = try { $error[0] | Where-Object { $_ -ne $null } | Select-Object -ExpandProperty InvocationInfo } catch { $null }
$ENV:DIYSHIP_STATUS = if ($null -ne $lastCmdletError -and $lastCmd.CommandLine -eq $lastCmdletError.Line) { 1 } else { $origLastExitCode }
}
$ENV:DIYSHIP_DURATION = [math]::Round(($lastCmd.EndExecutionTime - $lastCmd.StartExecutionTime).TotalMilliseconds)
}
Invoke-Native -Executable $DIYSHIP_COMMAND_LEFT
$global:LASTEXITCODE = $origLastExitCode
if ($global:? -ne $origDollarQuestion) {
if ($origDollarQuestion) {
1+1
} else {
Write-Error '' -ErrorAction 'Ignore'
}
}
}
# }}}