Skip to content

Commit 41f2ea7

Browse files
committed
updated powershell script
1 parent aa2e0a5 commit 41f2ea7

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/interceptors/terminal/terminal-scripts.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,31 @@ export const getFishShellScript = (callbackUrl: string, env: { [name: string]: s
124124
echo 'HTTP Toolkit interception enabled'
125125
`;
126126

127-
export const getPowerShellScript = (callbackUrl: string, env: { [name: string]: string }) => `${
128-
_.map(env, (value, key) => ` $Env:${key} = "${value.replace(/"/g, '`"')}"`).join('\n')
127+
export const getPowerShellScript = (callbackUrl: string, env: { [name: string]: string }) => `
128+
$HTTPTOOLKIT_envVars = Get-ChildItem Env:
129+
130+
${
131+
_.map(env, (value, key) => ` $Env:${key} = "${value.replace(/"/g, '`"')}"`).join('\n')
132+
}
133+
134+
function Stop-Toolkit {
135+
136+
#Remove every env
137+
$currentEnvVars = Get-ChildItem Env:
138+
foreach ($envVar in $currentEnvVars) {
139+
[System.Environment]::SetEnvironmentVariable($envVar.Name, $null)
140+
}
141+
142+
#Set the old env variables
143+
foreach ($var in $HTTPTOOLKIT_envVars) {
144+
[System.Environment]::SetEnvironmentVariable($var.Name, $var.Value)
145+
}
146+
147+
#Revert these two back to the default values
148+
$PSDefaultParameterValues.Remove("invoke-webrequest:proxy")
149+
$PSDefaultParameterValues.Remove("invoke-webrequest:SkipCertificateCheck")
150+
151+
Write-Host 'HTTP Toolkit interception disabled'
129152
}
130153
131154
# We add a few special hooks just for Invoke-WebRequest.
@@ -137,7 +160,8 @@ export const getPowerShellScript = (callbackUrl: string, env: { [name: string]:
137160
# Let the HTTP Toolkit app know this ran succesfully
138161
Start-Job -ScriptBlock { Invoke-WebRequest "${callbackUrl}" -NoProxy -Method 'POST' } | out-null
139162
140-
Write-Host 'HTTP Toolkit interception enabled'
163+
Write-Host "HTTP Toolkit interception enabled\`nTo stop intercepting type " -NoNewline
164+
Write-Host "Stop-Toolkit" -ForegroundColor Red
141165
`;
142166

143167
// Find the relevant user shell config file, add the above line to it, so that

0 commit comments

Comments
 (0)