-
Notifications
You must be signed in to change notification settings - Fork 3
/
Microsoft.PowerShellISE_Profile.ps1
61 lines (53 loc) · 3.84 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
New-PsDrive -Name Mod -PSProvider FileSystem -Root (($env:PSMODULEPATH -split ";")[0])
Import-Module ISEPack
Set-Alias Open PowerShell_ise
<#
This function is now built-in to the editor so it is no longer needed.
I'm keeping it here so you can see how it works.
function GoTo-Line
{
$ed = $psise.CurrentOpenedFile.Editor
[int]$l = read-host
if ($l -le $ed.LineCount)
{
$ed.SetCaretPosition($l,1)
}
else
{O
$ed.SetCaretPosition($ed.LineCount,1)
}
}
#>
function Edit-Selected
{
$ed = $psise.CurrentOpenedFile.Editor
PowerShell_ise $ed.SelectedText
}
function global:Export-SessionFiles
{
$psise.CurrentOpenedRunspace.OpenedFiles |%{
if (!$_.isSaved)
{
$title = "Save File?"
$message = "Do you want to Save `n`t$($_.FullPath)`nbefore exporting?"
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", `
"Save $($_.FullPath)."
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", `
"Export but do not save $($_.fullpath)."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
if (($host.ui.PromptForChoice($title, $message, $options, 0)) -eq 0)
{
$_.Save()
}
}
$psise.CurrentOpenedRunspace.Output.InsertText("`nExporting $($_.FullPath)")
$_.FullPath
} > ~/ISE-SessionFiles.txt
}
function Import-SessionFiles
{
cat ~/ISE-SessionFiles.txt | %{ $psise.CurrentOpenedRunspace.OpenedFiles.add($_) }
}
$null = $psISE.CustomMenu.Submenus.Add("Edit Selected", {Edit-Selected}, 'Ctrl+E')
$null = $psISE.CustomMenu.Submenus.Add("Export Session Files", {Export-SessionFiles}, 'Ctrl+SHIFT+E')
$null = $psISE.CustomMenu.Submenus.Add("Import Session Files", {Import-SessionFiles}, 'Ctrl+SHIFT+I')