-
-
Notifications
You must be signed in to change notification settings - Fork 271
/
Open-ISEFunction.ps1
40 lines (32 loc) · 1.34 KB
/
Open-ISEFunction.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
function Open-ISEFunction {
<#
.SYNOPSIS
Open a function in ISE
.DESCRIPTION
Open a function in ISE. Any function that can be obtained by (get-command <command>).definition. Pretty much anything that isn't compiled in a DLL or obfuscated in some other manner.
.FUNCTIONALITY
General Command
#>
[cmdletbinding()]
param(
#In the validation block, check if input is a function and get the definition
[ValidateScript({ Get-Command -commandtype function -name $_ })]
[string[]]$function
)
foreach($fn in $function){
#Get the definition
$definition = (Get-Command -commandtype function -name $fn).definition
#If the definition exists, add a new tab with the contents.
if($definition){
#Definition won't include function keyword. Add it.
$definition = "function $fn { $definition }"
#Add the file and definition content
$tab = $psise.CurrentPowerShellTab.files.Add()
$tab.editor.text = $definition
#set the caret to column 1 line 1
$tab.editor.SetCaretPosition(1,1)
#Sleep a few milliseconds. Not sure why but omitting this has caused issues for me.
start-sleep -Milliseconds 200
}
}
}