-
-
Notifications
You must be signed in to change notification settings - Fork 19
PowerShellFar run from editor
PowerShell scripts in Far Manager editor may be simply invoked by pressing F5.
Scripts are invoked in the main session with their own scope. Similar PowerShell commands for normal scripts are:
ps: & "C:\...\MyScript.ps1"
In addition, PowerShellFar recognizes and invokes special Invoke-Build
scripts *.build.ps1
and *.test.ps1
.
Similar PowerShell commands are (given <task>
is the editor caret task):
ps: Invoke-Build -Task <task> -File "C:\...\MyScript.build.ps1"
Running by F5 is ideal for composing scripts and trying them immediately.
But this is not possible right away if a script requires certain input parameters.
Fortunately, $PSDefaultParameterValues
helps.
See about_Parameters_Default_Values and below examples.
Given the script MyScript.ps1
with the parameter Configuration
:
param(
[string]$Configuration
)
...
In order to run it by F5 with Configuration
set to some value, do:
ps: $PSDefaultParameterValues['MyScript.ps1:Configuration'] = 'Release'
NOTE All scripts named
MyScript.ps1
withConfiguration
may be affected. This may or may not be desired.
The similar trick works for build scripts but the target command should be
Invoke-Build.ps1
, the actual runner, not the build script name:
ps: $PSDefaultParameterValues['Invoke-Build.ps1:Configuration'] = 'Release'
NOTE All build scripts with the parameter
Configuration
may be affected. This may or may not be desired.