Last active
August 29, 2015 14:04
-
-
Save sunnyone/aaa2aef559ae7b765be5 to your computer and use it in GitHub Desktop.
A script sharpens PowerShell ISE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install (simple way) | |
# Write this code to "%USERPROFILE%\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1" | |
# Install (module way) | |
# Place this script to "%USERPROFILE\Documents\WindowsPowerShell\Modules\UseLayoutRounding\UseLayoutRounding.psm1" and | |
# write "Import-Module UseLayoutRounding" to Microsoft.PowerShellISE_profile.ps1 | |
Add-Type -TypeDefinition @" | |
using System; | |
using System.Collections.Generic; | |
using System.Reflection; | |
using System.Threading; | |
public static class UseLayoutRounding | |
{ | |
public static void Setup(object psISE) | |
{ | |
var host = psISE.GetType().Assembly.GetType("Microsoft.Windows.PowerShell.Gui.Internal.PSGInternalHost"); | |
var mainWindowField = host.GetField("mainWindow", BindingFlags.NonPublic | BindingFlags.Static); | |
var mainWindow = mainWindowField.GetValue(null); | |
var useLayoutRoudingMethod = mainWindow.GetType().GetProperty("UseLayoutRounding").GetSetMethod(); | |
var syncCtxField = host.GetField("synchronizationContext", BindingFlags.NonPublic | BindingFlags.Static); | |
var syncCtx = (SynchronizationContext) syncCtxField.GetValue(null); | |
syncCtx.Post(x => | |
{ | |
useLayoutRoudingMethod.Invoke(mainWindow, new object[] {true}); | |
}, null); | |
} | |
} | |
"@ | |
[UseLayoutRounding]::Setup($psISE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment