-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNew-Shell.ps1
75 lines (68 loc) · 2.32 KB
/
New-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
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
70
71
72
73
74
75
<#
.SYNOPSIS
Create new Shell
.DESCRIPTION
Initializes shell/env for application
.PARAMETER Type
Type of shell we want to create
.EXAMPLE
New-Shell -Type SSH
.NOTES
With Type specified as Pwsh it opens an elevated prompt
Calling without a type specified opens a regular pwsh
* Once in a while, Pwsh shell's cannot invoke Start-Process
(feels like cmdlet call is dangled, stderr/stdout probably is the reason)
#>
[CmdletBinding()] Param (
[string] $Type = ''
)
function InvokeNewShell() {
# For apps that are just short cut commands
switch( $Type ) {
'Pwsh' { # elevated
Push-Location $PwshScriptDir
Start-Process pwsh -ArgumentList '-NoExit', '-NoLogo', 'Init-App.ps1 admin' -ErrorAction 'Stop' -Verb Runas
Pop-Location
}
'dotnet' {
Push-Location $PwshScriptDir
Start-Process pwsh -ErrorAction 'Stop' -ArgumentList '-NoExit', '-NoLogo', '-Command', `
{ `
(Get-Host).UI.RawUI.WindowTitle = 'dotnet Shell' ; `
Init-App.ps1 dotnet `
}
Pop-Location
}
'SSH' {
Push-Location $PwshScriptDir
Start-Process pwsh -ArgumentList '-NoExit', '-NoLogo', 'Init-App.ps1 openssh' -ErrorAction 'Stop'
Pop-Location
}
'Node' {
Push-Location $PwshScriptDir
Start-Process pwsh -ArgumentList '-NoExit', '-NoLogo', 'Init-App.ps1 node' -ErrorAction 'Stop'
Pop-Location
}
'Powershell' {
Start-Process Powershell -ErrorAction 'Stop' -ArgumentList '-NoExit', '-NoLogo', '-Command', `
{ (Get-Host).UI.RawUI.WindowTitle = 'Qubit Powershell' }
}
'Cmd' { # elevated
Push-Location $PwshScriptDir
'FYI: Utilize Run Dialog for a regular cmd process (not elevated)'
Start-Process cmd -ArgumentList '-NoExit', '-NoLogo', 'Init-App.ps1 admin' -ErrorAction 'Stop' -Verb Runas
Pop-Location
}
'Meta' { # elevated
Push-Location $PwshScriptDir
Start-Process pwsh -ArgumentList '-NoExit', '-NoLogo', 'Init-App.ps1 meta' -ErrorAction 'Stop' -Verb Runas
Pop-Location
}
default {
'Invoking default shell..'
Start-Process pwsh -ErrorAction 'Stop' -ArgumentList '-NoExit', '-NoLogo', '-Command', `
{ (Get-Host).UI.RawUI.WindowTitle = 'Matrix Terminal' }
}
}
}
InvokeNewShell