-
Notifications
You must be signed in to change notification settings - Fork 4
/
Microsoft.PowerShellISE_profile.ps1
69 lines (59 loc) · 1.91 KB
/
Microsoft.PowerShellISE_profile.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
$ProfileDir = (split-path $MyInvocation.MyCommand.Path -Parent)
Push-Location $ProfileDir
. ./PowerShell.ps1
. ./Themes/blackboard.ps1
Pop-Location
function ISE-CommentSelectedText {
$text = $psISE.CurrentFile.Editor.SelectedText
$lines = $text.Split("`n") | %{
$_ -replace "^", "# "
}
if ($lines[$lines.count -1] -eq "# ") {
$lines[$lines.count -1] = ""
}
$text = [string]::Join("`n", $lines)
$psISE.CurrentFile.Editor.InsertText($text)
}
function ISE-UncommentSelectedText {
$text = $psISE.CurrentFile.Editor.SelectedText
$lines = $text.Split("`n") | %{
$_ -replace "^ *# *", ""
}
$text = [string]::Join("`n", $lines)
$psISE.CurrentOpenedFile.Editor.InsertText($text)
}
function ISE-ToggleCommenting {
if ($psISE.CurrentFile.Editor.SelectedText.StartsWith('#')) {
ISE-UncommentSelectedText
}
else {
ISE-CommentSelectedText
}
}
function Set-File {
param
(
[parameter(Mandatory=$true,ValueFromPipeline=$true)]
[string]
$file
)
$psise.CurrentOpenedRunspace.OpenedFiles.Add($file)
}
function Insert-Text{
param
(
[parameter(Mandatory=$true, ValueFromPipeline=$true)]
[string]
$text
)
$currentFilePath = $psise.CurrentOpenedFile.FullPath
$currentFile = $psIse.CurrentOpenedRunspace.OpenedFiles | where {$_.FullPath -eq $currentFilePath}
$currentFile.Editor.InsertText($text)
}
function Invoke-CaretLine
{
Invoke-Expression $([Regex]::Split($psISE.CurrentOpenedFile.Editor.text,"`r`n" )[$psISE.CurrentOpenedFile.Editor.caretline-1])
}
[void]$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Current Line", {Invoke-CaretLine},'F7')
[void]$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add('Toggle Commenting', {ISE-ToggleCommenting}, "Ctrl+Oem2")
[void]$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("C_lear", {clear}, "Ctrl+L")