PowerShell ISE 是编写 PowerShell 脚本最重要的环境。熟练掌握 ISE 的快捷键有以下好处:
- 逼格高(这个很重要)
- 提高效率
- 预防腕管炎
- ……(请自行脑补)
其实,所有快捷键的定义都在 ISE 的 Microsoft.PowerShell.GPowerShell
(DLL)中。我们首先需要获取这个 DLL 的引用。
1 2 3 4 5 6
| PS> $gps = $psISE.GetType().Assembly PS> $gps
GAC Version Location --- ------- -------- True v4.0.30319 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.PowerShell.GPowerShell\...
|
然后我们可以获取这个程序集的资源列表:
1 2 3 4
| PS> $gps.GetManifestResourceNames()
Microsoft.PowerShell.GPowerShell.g.resources GuiStrings.resources
|
然后我们创建一个 ResourceManager
对象来存取程序集中的资源。在构造函数中将需要打开的资源名(去掉 .resources 扩展名)以及包含资源的程序集对象传给它。
1
| $rm = New-Object System.Resources.ResourceManager GuiStrings,$gps
|
剩下只要调用 GetResourceSet()
方法根据特定的文化信息获取资源。
1 2 3 4 5 6 7 8 9 10 11 12
| $rs = $rm.GetResourceSet((Get-Culture),$true,$true) $rs
Name Value ---- ----- SnippetToolTipPath 路径: {0} MediumSlateBlueColorName 中石板蓝色 > EditorBoxSelectLineDownShor... Alt+Shift+Down NewRunspace 新建 PowerShell 选项卡(_E) > EditorSelectToPreviousChara... Shift+Left > RemoveAllBreakpointsShortcut Ctrl+Shift+F9 SaveScriptQuestion 是否保存 {0}?
|
查看输出结果,我们可以发现包含“>”的几行类似按键组合信息。如果您仔细查看输出结果,将会发现规律是 Name
以 Shortcut
结尾(有可能包含数字),以及以 F
开头加 1 至 2 位数字并带有 Keyboard
关键字的。通过下面一行代码,我们可以过滤出所有和键盘有关系的项目并对它们进行排序。
1
| $rs | where Name -match 'Shortcut\d?$|^F\d+Keyboard' | Sort-Object Value
|
以下是完整的代码片段和完整的结果:
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| $gps = $psISE.GetType().Assembly $rm = New-Object System.Resources.ResourceManager GuiStrings,$gps $rs = $rm.GetResourceSet((Get-Culture),$true,$true) $rs | where Name -match 'Shortcut\d?$|^F\d+Keyboard' | Sort-Object Value | Format-Table -AutoSize
Name Value ---- ----- EditorUndoShortcut2 Alt+Backspace EditorSelectNextSiblingShortcut Alt+Down ExitShortcut Alt+F4 EditorSelectEnclosingShortcut Alt+Left EditorSelectFirstChildShortcut Alt+Right EditorRedoShortcut2 Alt+Shift+Backspace EditorBoxSelectLineDownShortcut Alt+Shift+Down ToggleHorizontalAddOnPaneShortcut Alt+Shift+H EditorBoxSelectToPreviousCharacterShortcut Alt+Shift+Left EditorBoxSelectToNextCharacterShortcut Alt+Shift+Right EditorTransposeLineShortcut Alt+Shift+T EditorBoxSelectLineUpShortcut Alt+Shift+Up ToggleVerticalAddOnPaneShortcut Alt+Shift+V EditorSelectPreviousSiblingShortcut Alt+Up ShowScriptPaneTopShortcut Ctrl+1 ShowScriptPaneRightShortcut Ctrl+2 ShowScriptPaneMaximizedShortcut Ctrl+3 EditorSelectAllShortcut Ctrl+A ZoomIn1Shortcut Ctrl+Add EditorMoveCurrentLineToBottomShortcut Ctrl+Alt+End EditorMoveCurrentLineToTopShortcut Ctrl+Alt+Home EditorDeleteWordToLeftShortcut Ctrl+Backspace StopExecutionShortcut Ctrl+Break StopAndCopyShortcut Ctrl+C GoToConsoleShortcut Ctrl+D EditorDeleteWordToRightShortcut Ctrl+Del EditorScrollDownAndMoveCaretIfNecessaryShortcut Ctrl+Down EditorMoveToEndOfDocumentShortcut Ctrl+End FindShortcut Ctrl+F ShowCommandShortcut Ctrl+F1 CloseScriptShortcut Ctrl+F4 GoToLineShortcut Ctrl+G ReplaceShortcut Ctrl+H EditorMoveToStartOfDocumentShortcut Ctrl+Home GoToEditorShortcut Ctrl+I Copy2Shortcut Ctrl+Ins ShowSnippetShortcut Ctrl+J EditorMoveToPreviousWordShortcut Ctrl+Left ToggleOutliningExpansionShortcut Ctrl+M ZoomOut3Shortcut Ctrl+Minus NewScriptShortcut Ctrl+N OpenScriptShortcut Ctrl+O GoToMatchShortcut Ctrl+Oem6 ZoomIn3Shortcut Ctrl+Plus ToggleScriptPaneShortcut Ctrl+R EditorMoveToNextWordShortcut Ctrl+Right SaveScriptShortcut Ctrl+S ZoomIn2Shortcut Ctrl+Shift+Add GetCallStackShortcut Ctrl+Shift+D EditorSelectToEndOfDocumentShortcut Ctrl+Shift+End RemoveAllBreakpointsShortcut Ctrl+Shift+F9 HideHorizontalAddOnToolShortcut Ctrl+Shift+H EditorSelectToStartOfDocumentShortcut Ctrl+Shift+Home ListBreakpointsShortcut Ctrl+Shift+L EditorSelectToPreviousWordShortcut Ctrl+Shift+Left ZoomOut4Shortcut Ctrl+Shift+Minus StartPowerShellShortcut Ctrl+Shift+P ZoomIn4Shortcut Ctrl+Shift+Plus NewRemotePowerShellTabShortcut Ctrl+Shift+R EditorSelectToNextWordShortcut Ctrl+Shift+Right ZoomOut2Shortcut Ctrl+Shift+Subtract EditorMakeUppercaseShortcut Ctrl+Shift+U HideVerticalAddOnToolShortcut Ctrl+Shift+V IntellisenseShortcut Ctrl+Space ZoomOut1Shortcut Ctrl+Subtract NewRunspaceShortcut Ctrl+T EditorMakeLowercaseShortcut Ctrl+U EditorScrollUpAndMoveCaretIfNecessaryShortcut Ctrl+Up Paste1Shortcut Ctrl+V CloseRunspaceShortcut Ctrl+W Cut1Shortcut Ctrl+X EditorRedoShortcut1 Ctrl+Y EditorUndoShortcut1 Ctrl+Z F1KeyboardDisplayName F1 HelpShortcut F1 StepOverShortcut F10 F10KeyboardDisplayName F10 StepIntoShortcut F11 F11KeyboardDisplayName F11 F12KeyboardDisplayName F12 F2KeyboardDisplayName F2 FindNextShortcut F3 F3KeyboardDisplayName F3 F4KeyboardDisplayName F4 RunScriptShortcut F5 F5KeyboardDisplayName F5 F6KeyboardDisplayName F6 F7KeyboardDisplayName F7 RunSelectionShortcut F8 F8KeyboardDisplayName F8 F9KeyboardDisplayName F9 ToggleBreakpointShortcut F9 EditorDeleteCharacterToLeftShortcut Shift+Backspace Cut2Shortcut Shift+Del EditorSelectLineDownShortcut Shift+Down EditorSelectToEndOfLineShortcut Shift+End EditorInsertNewLineShortcut Shift+Enter StepOutShortcut Shift+F11 FindPreviousShortcut Shift+F3 StopDebuggerShortcut Shift+F5 EditorSelectToStartOfLineShortcut Shift+Home Paste2Shortcut Shift+Ins EditorSelectToPreviousCharacterShortcut Shift+Left EditorSelectPageDownShortcut Shift+PgDn EditorSelectPageUpShortcut Shift+PgUp EditorSelectToNextCharacterShortcut Shift+Right EditorSelectLineUpShortcut Shift+Up
|