1
1
2
- # This is an example profile for PSReadline .
2
+ # This is an example profile for PSReadLine .
3
3
#
4
4
# This is roughly what I use so there is some emphasis on emacs bindings,
5
5
# but most of these bindings make sense in Windows mode as well.
@@ -21,14 +21,14 @@ Set-PSReadLineOption -HistoryNoDuplicates
21
21
# when you used up arrow, which can be useful if you forget the exact
22
22
# string you started the search on.
23
23
Set-PSReadLineOption - HistorySearchCursorMovesToEnd
24
- Set-PSReadlineKeyHandler - Key Ctrl+ P - Function HistorySearchBackward
25
- Set-PSReadlineKeyHandler - Key Ctrl+ N - Function HistorySearchForward
24
+ Set-PSReadLineKeyHandler - Key Ctrl+ p - Function HistorySearchBackward
25
+ Set-PSReadLineKeyHandler - Key Ctrl+ n - Function HistorySearchForward
26
26
27
27
# This key handler shows the entire or filtered history using Out-GridView. The
28
28
# typed text is used as the substring pattern for filtering. A selected command
29
29
# is inserted to the command line without invoking. Multiple command selection
30
30
# is supported, e.g. selected by Ctrl + Click.
31
- Set-PSReadlineKeyHandler - Key F7 `
31
+ Set-PSReadLineKeyHandler - Key F7 `
32
32
- BriefDescription History `
33
33
- LongDescription ' Show command history' `
34
34
- ScriptBlock {
@@ -42,7 +42,7 @@ Set-PSReadlineKeyHandler -Key F7 `
42
42
$history = [System.Collections.ArrayList ]@ (
43
43
$last = ' '
44
44
$lines = ' '
45
- foreach ($line in [System.IO.File ]::ReadLines((Get-PSReadlineOption ).HistorySavePath))
45
+ foreach ($line in [System.IO.File ]::ReadLines((Get-PSReadLineOption ).HistorySavePath))
46
46
{
47
47
if ($line.EndsWith (' `' ))
48
48
{
@@ -83,38 +83,38 @@ Set-PSReadlineKeyHandler -Key F7 `
83
83
84
84
# This is an example of a macro that you might use to execute a command.
85
85
# This will add the command to history.
86
- Set-PSReadlineKeyHandler - Key Ctrl+ B `
87
- - BriefDescription BuildCurrentDirectory `
88
- - LongDescription " Build the current directory" `
89
- - ScriptBlock {
90
- [Microsoft.PowerShell.PSConsoleReadLine ]::RevertLine()
91
- [Microsoft.PowerShell.PSConsoleReadLine ]::Insert(" msbuild" )
92
- [Microsoft.PowerShell.PSConsoleReadLine ]::AcceptLine()
93
- }
86
+ # Set-PSReadLineKeyHandler -Key Ctrl+b `
87
+ # -BriefDescription BuildCurrentDirectory `
88
+ # -LongDescription "Build the current directory" `
89
+ # -ScriptBlock {
90
+ # [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
91
+ # [Microsoft.PowerShell.PSConsoleReadLine]::Insert("msbuild")
92
+ # [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
93
+ # }
94
94
95
95
# In Emacs mode - Tab acts like in bash, but the Windows style completion
96
96
# is still useful sometimes, so bind some keys so we can do both
97
- Set-PSReadlineKeyHandler - Key Ctrl+ Q - Function TabCompleteNext
98
- Set-PSReadlineKeyHandler - Key Ctrl+ Shift + Q - Function TabCompletePrevious
97
+ Set-PSReadLineKeyHandler - Key Ctrl+ q - Function TabCompleteNext
98
+ Set-PSReadLineKeyHandler - Key Ctrl+ Q - Function TabCompletePrevious
99
99
100
100
# Clipboard interaction is bound by default in Windows mode, but not Emacs mode.
101
- Set-PSReadlineKeyHandler - Key Shift+ Ctrl+ C - Function Copy
102
- Set-PSReadlineKeyHandler - Key Ctrl+ V - Function Paste
101
+ Set-PSReadLineKeyHandler - Key Shift+ Ctrl+ C - Function Copy
102
+ Set-PSReadLineKeyHandler - Key Ctrl+ V - Function Paste
103
103
104
104
# CaptureScreen is good for blog posts or email showing a transaction
105
105
# of what you did when asking for help or demonstrating a technique.
106
- Set-PSReadlineKeyHandler - Chord ' Ctrl+D,Ctrl+C' - Function CaptureScreen
106
+ Set-PSReadLineKeyHandler - Chord ' Ctrl+D,Ctrl+C' - Function CaptureScreen
107
107
108
108
# The built-in word movement uses character delimiters, but token based word
109
109
# movement is also very useful - these are the bindings you'd use if you
110
110
# prefer the token based movements bound to the normal emacs word movement
111
111
# key bindings.
112
- Set-PSReadlineKeyHandler - Key Alt+ D - Function ShellKillWord
113
- Set-PSReadlineKeyHandler - Key Alt+ Backspace - Function ShellBackwardKillWord
114
- Set-PSReadlineKeyHandler - Key Alt+ B - Function ShellBackwardWord
115
- Set-PSReadlineKeyHandler - Key Alt+ F - Function ShellForwardWord
116
- Set-PSReadlineKeyHandler - Key Shift+ Alt+ B - Function SelectShellBackwardWord
117
- Set-PSReadlineKeyHandler - Key Shift+ Alt+ F - Function SelectShellForwardWord
112
+ Set-PSReadLineKeyHandler - Key Alt+ D - Function ShellKillWord
113
+ Set-PSReadLineKeyHandler - Key Alt+ Backspace - Function ShellBackwardKillWord
114
+ Set-PSReadLineKeyHandler - Key Alt+ B - Function ShellBackwardWord
115
+ Set-PSReadLineKeyHandler - Key Alt+ F - Function ShellForwardWord
116
+ Set-PSReadLineKeyHandler - Key Shift+ Alt+ B - Function SelectShellBackwardWord
117
+ Set-PSReadLineKeyHandler - Key Shift+ Alt+ F - Function SelectShellForwardWord
118
118
119
119
# region Smart Insert/Delete
120
120
@@ -123,7 +123,7 @@ Set-PSReadlineKeyHandler -Key Shift+Alt+F -Function SelectShellForwardWord
123
123
# in the module that do this, but this implementation still isn't as smart
124
124
# as ReSharper, so I'm just providing it as a sample.
125
125
126
- Set-PSReadlineKeyHandler - Key ' "' , " '" `
126
+ Set-PSReadLineKeyHandler - Key ' "' , " '" `
127
127
- BriefDescription SmartInsertQuote `
128
128
- LongDescription " Insert paired quotes if not already on a quote" `
129
129
- ScriptBlock {
@@ -145,7 +145,7 @@ Set-PSReadlineKeyHandler -Key '"',"'" `
145
145
}
146
146
}
147
147
148
- Set-PSReadlineKeyHandler - Key ' (' , ' {' , ' [' `
148
+ Set-PSReadLineKeyHandler - Key ' (' , ' {' , ' [' `
149
149
- BriefDescription InsertPairedBraces `
150
150
- LongDescription " Insert matching braces" `
151
151
- ScriptBlock {
@@ -165,7 +165,7 @@ Set-PSReadlineKeyHandler -Key '(','{','[' `
165
165
[Microsoft.PowerShell.PSConsoleReadLine ]::SetCursorPosition($cursor - 1 )
166
166
}
167
167
168
- Set-PSReadlineKeyHandler - Key ' )' , ' ]' , ' }' `
168
+ Set-PSReadLineKeyHandler - Key ' )' , ' ]' , ' }' `
169
169
- BriefDescription SmartCloseBraces `
170
170
- LongDescription " Insert closing brace or skip" `
171
171
- ScriptBlock {
@@ -185,7 +185,7 @@ Set-PSReadlineKeyHandler -Key ')',']','}' `
185
185
}
186
186
}
187
187
188
- Set-PSReadlineKeyHandler - Key Backspace `
188
+ Set-PSReadLineKeyHandler - Key Backspace `
189
189
- BriefDescription SmartBackspace `
190
190
- LongDescription " Delete previous character or matching quotes/parens/braces" `
191
191
- ScriptBlock {
@@ -227,7 +227,7 @@ Set-PSReadlineKeyHandler -Key Backspace `
227
227
# This binding will let you save that command in the history so you can recall it,
228
228
# but it doesn't actually execute. It also clears the line with RevertLine so the
229
229
# undo stack is reset - though redo will still reconstruct the command line.
230
- Set-PSReadlineKeyHandler - Key Alt+ w `
230
+ Set-PSReadLineKeyHandler - Key Alt+ w `
231
231
- BriefDescription SaveInHistory `
232
232
- LongDescription " Save current line in history but do not execute" `
233
233
- ScriptBlock {
@@ -241,7 +241,7 @@ Set-PSReadlineKeyHandler -Key Alt+w `
241
241
}
242
242
243
243
# Insert text from the clipboard as a here string
244
- Set-PSReadlineKeyHandler - Key Ctrl+ Shift+ v `
244
+ Set-PSReadLineKeyHandler - Key Ctrl+ Shift+ v `
245
245
- BriefDescription PasteAsHereString `
246
246
- LongDescription " Paste the clipboard text as a here string" `
247
247
- ScriptBlock {
@@ -263,7 +263,7 @@ Set-PSReadlineKeyHandler -Key Ctrl+Shift+v `
263
263
# Sometimes you want to get a property of invoke a member on what you've entered so far
264
264
# but you need parens to do that. This binding will help by putting parens around the current selection,
265
265
# or if nothing is selected, the whole line.
266
- Set-PSReadlineKeyHandler - Key ' Alt+(' `
266
+ Set-PSReadLineKeyHandler - Key ' Alt+(' `
267
267
- BriefDescription ParenthesizeSelection `
268
268
- LongDescription " Put parenthesis around the selection or entire line and move the cursor to after the closing parenthesis" `
269
269
- ScriptBlock {
@@ -291,7 +291,7 @@ Set-PSReadlineKeyHandler -Key 'Alt+(' `
291
291
# Each time you press Alt+', this key handler will change the token
292
292
# under or before the cursor. It will cycle through single quotes, double quotes, or
293
293
# no quotes each time it is invoked.
294
- Set-PSReadlineKeyHandler - Key " Alt+'" `
294
+ Set-PSReadLineKeyHandler - Key " Alt+'" `
295
295
- BriefDescription ToggleQuoteArgument `
296
296
- LongDescription " Toggle quotes on the argument under the cursor" `
297
297
- ScriptBlock {
@@ -353,7 +353,7 @@ Set-PSReadlineKeyHandler -Key "Alt+'" `
353
353
}
354
354
355
355
# This example will replace any aliases on the command line with the resolved commands.
356
- Set-PSReadlineKeyHandler - Key " Alt+%" `
356
+ Set-PSReadLineKeyHandler - Key " Alt+%" `
357
357
- BriefDescription ExpandAliases `
358
358
- LongDescription " Replace all aliases with the full command" `
359
359
- ScriptBlock {
@@ -393,7 +393,7 @@ Set-PSReadlineKeyHandler -Key "Alt+%" `
393
393
}
394
394
395
395
# F1 for help on the command line - naturally
396
- Set-PSReadlineKeyHandler - Key F1 `
396
+ Set-PSReadLineKeyHandler - Key F1 `
397
397
- BriefDescription CommandHelp `
398
398
- LongDescription " Open the help window for the current command" `
399
399
- ScriptBlock {
@@ -438,47 +438,47 @@ Set-PSReadlineKeyHandler -Key F1 `
438
438
# needing to type cd and won't change the command line.
439
439
440
440
#
441
- $global :PSReadlineMarks = @ {}
441
+ $global :PSReadLineMarks = @ {}
442
442
443
- Set-PSReadlineKeyHandler - Key Ctrl+ Shift+ j `
443
+ Set-PSReadLineKeyHandler - Key Ctrl+ Shift+ j `
444
444
- BriefDescription MarkDirectory `
445
445
- LongDescription " Mark the current directory" `
446
446
- ScriptBlock {
447
447
param ($key , $arg )
448
448
449
449
$key = [Console ]::ReadKey($true )
450
- $global :PSReadlineMarks [$key.KeyChar ] = $pwd
450
+ $global :PSReadLineMarks [$key.KeyChar ] = $pwd
451
451
}
452
452
453
- Set-PSReadlineKeyHandler - Key Ctrl+ j `
453
+ Set-PSReadLineKeyHandler - Key Ctrl+ j `
454
454
- BriefDescription JumpDirectory `
455
455
- LongDescription " Goto the marked directory" `
456
456
- ScriptBlock {
457
457
param ($key , $arg )
458
458
459
459
$key = [Console ]::ReadKey()
460
- $dir = $global :PSReadlineMarks [$key.KeyChar ]
460
+ $dir = $global :PSReadLineMarks [$key.KeyChar ]
461
461
if ($dir )
462
462
{
463
463
cd $dir
464
464
[Microsoft.PowerShell.PSConsoleReadLine ]::InvokePrompt()
465
465
}
466
466
}
467
467
468
- Set-PSReadlineKeyHandler - Key Alt+ j `
468
+ Set-PSReadLineKeyHandler - Key Alt+ j `
469
469
- BriefDescription ShowDirectoryMarks `
470
470
- LongDescription " Show the currently marked directories" `
471
471
- ScriptBlock {
472
472
param ($key , $arg )
473
473
474
- $global :PSReadlineMarks .GetEnumerator () | % {
474
+ $global :PSReadLineMarks .GetEnumerator () | % {
475
475
[PSCustomObject ]@ {Key = $_.Key ; Dir = $_.Value } } |
476
476
Format-Table - AutoSize | Out-Host
477
477
478
478
[Microsoft.PowerShell.PSConsoleReadLine ]::InvokePrompt()
479
479
}
480
480
481
- Set-PSReadlineOption - CommandValidationHandler {
481
+ Set-PSReadLineOption - CommandValidationHandler {
482
482
param ([System.Management.Automation.Language.CommandAst ]$CommandAst )
483
483
484
484
switch ($CommandAst.GetCommandName ())
@@ -497,7 +497,7 @@ Set-PSReadlineOption -CommandValidationHandler {
497
497
}
498
498
499
499
# ghq + peco
500
- Set-PSReadlineKeyHandler - Key Ctrl+ ] `
500
+ Set-PSReadLineKeyHandler - Key Ctrl+ ] `
501
501
- BriefDescription SelectGHQDirectory `
502
502
- LongDescription " Jump to the directory managed by ghq" `
503
503
- ScriptBlock {
0 commit comments