-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathintelli-shell.ps1
66 lines (57 loc) · 3.31 KB
/
intelli-shell.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
$IntelliSearchChord = if ($null -eq $env:INTELLI_SEARCH_HOTKEY) { 'Ctrl+Spacebar' } else { $env:INTELLI_SEARCH_HOTKEY }
$IntelliBookmarkChord = if ($null -eq $env:INTELLI_BOOKMARK_HOTKEY) { 'Ctrl+b' } else { $env:INTELLI_BOOKMARK_HOTKEY }
$IntelliLabelChord = if ($null -eq $env:INTELLI_LABEL_HOTKEY) { 'Ctrl+l' } else { $env:INTELLI_LABEL_HOTKEY }
Set-PSReadLineKeyHandler -Chord $IntelliSearchChord -BriefDescription "IntelliShell Search" -Description "Searches for a bookmarked command" -ScriptBlock {
$line = $null
$cursor = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
$TempFile = New-TemporaryFile
$line = $line -replace '"','""""""""""""'
$Command = 'intelli-shell.exe --file-output=""""' + $TempFile.FullName + '"""" search """"' + $line + '""""'
Start-Process powershell.exe -Wait -NoNewWindow -ArgumentList "-command", "$Command"
$IntelliOutput = Get-Content -Raw $TempFile
Remove-Item $TempFile
[Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
[Microsoft.PowerShell.PSConsoleReadLine]::BeginningOfLine()
[Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
if (-Not [string]::IsNullOrWhiteSpace($IntelliOutput)) {
[Microsoft.PowerShell.PSConsoleReadLine]::Insert($IntelliOutput)
}
}
Set-PSReadLineKeyHandler -Chord $IntelliBookmarkChord -BriefDescription "IntelliShell Bookmark" -Description "Bookmarks current command" -ScriptBlock {
$line = $null
$cursor = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
$TempFile = New-TemporaryFile
$line = $line -replace '"','""""""""""""'
$Command = 'intelli-shell.exe --file-output=""""' + $TempFile.FullName + '"""" new -c """"' + $line + '""""'
if ([string]::IsNullOrWhiteSpace($line)) {
$Command = 'intelli-shell.exe --file-output=""""' + $TempFile.FullName + '"""" new'
}
Start-Process powershell.exe -Wait -NoNewWindow -ArgumentList "-command", "$Command"
$IntelliOutput = Get-Content -Raw $TempFile
Remove-Item $TempFile
[Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
[Microsoft.PowerShell.PSConsoleReadLine]::BeginningOfLine()
[Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
if (-Not [string]::IsNullOrWhiteSpace($IntelliOutput)) {
[Microsoft.PowerShell.PSConsoleReadLine]::Insert($IntelliOutput)
}
}
Set-PSReadLineKeyHandler -Chord $IntelliLabelChord -BriefDescription "IntelliShell Label" -Description "Triggers label replace for current command" -ScriptBlock {
$line = $null
$cursor = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
$TempFile = New-TemporaryFile
$line = $line -replace '"','""""""""""""'
$Command = 'intelli-shell.exe --file-output=""""' + $TempFile.FullName + '"""" label """"' + $line + '""""'
Start-Process powershell.exe -Wait -NoNewWindow -ArgumentList "-command", "$Command"
$IntelliOutput = Get-Content -Raw $TempFile
Remove-Item $TempFile
[Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
[Microsoft.PowerShell.PSConsoleReadLine]::BeginningOfLine()
[Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
if (-Not [string]::IsNullOrWhiteSpace($IntelliOutput)) {
[Microsoft.PowerShell.PSConsoleReadLine]::Insert($IntelliOutput)
}
}