-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefe.ps1
61 lines (51 loc) · 1.04 KB
/
defe.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
<#
.SYNOPSIS
Edit a command definition
.PARAMETER File
Command to edit
#>
param(
[Parameter(Mandatory=$true)]
[string] $File
)
$script:ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
$cmds = @(Get-Command $File -All)
if ($cmds.Length -ne 1) {
$cmds
Write-Warning "$File not a unique command"
}
$cmd = $cmds[0]
switch ($cmd.CommandType) {
Application {
$extension = [System.IO.Path]::GetExtension($cmd.Source)
if (Test-Shebang $cmd.Source) {
code $cmd.Source
}
elseif ($extension -and $extension -ne ".exe") {
code $cmd.Source
}
else {
"[binary]"
}
}
Function {
if ($cmd.ScriptBlock.File) {
$defLine = @(Select-String "^function $($cmd.Name)" $cmd.ScriptBlock.File)
if ($defLine.Length -eq 1) {
code --goto "$($cmd.ScriptBlock.File):$($defLine[0].LineNumber)"
} else {
code "$($cmd.ScriptBlock.File)"
}
}
else {
"[interactive function]"
}
}
ExternalScript {
code $cmd.Source
}
default {
$cmd
}
}