I hereby claim:
- I am seeminglyscience on github.
- I am seeminglyscience (https://keybase.io/seeminglyscience) on keybase.
- I have a public key ASByLYoy3uC2073UIRtV7Wp4j0izqlOV_73_fJVoze_DJAo
To claim this, I am signing this object:
| if ($psEditor) { | |
| # Don't reference any files whose FullName match this regex. | |
| ${Exclude Files Regex} = '\\Release\\|\\\.vscode\\|build.*\.ps1|debugHarness\.ps1|\.psd1' | |
| # Get the PowerShellEditorServices assemblies. | |
| ${editor services assemblies} = [System.AppDomain]::CurrentDomain.GetAssemblies() | | |
| Where-Object Location -Match 'PowerShell.EditorServices.*.dll' | | |
| ForEach-Object -MemberName Location | |
| # Add some C# that essentially lets us add a hook to the event that is called when VSCode opens a file. | |
| Add-Type -Language CSharp -ReferencedAssemblies ${editor services assemblies} -WarningAction SilentlyContinue -TypeDefinition @' |
I hereby claim:
To claim this, I am signing this object:
| # https://seeminglyscience.github.io/powershell/2017/04/13/cmdlet-creation-with-powershell | |
| using namespace System.Management.Automation | |
| using namespace System.Reflection | |
| [Cmdlet([VerbsDiagnostic]::Test, 'Cmdlet')] | |
| class TestCmdletCommand : PSCmdlet { | |
| [Parameter(ValueFromPipeline)] | |
| [object] | |
| $InputObject; |
| using namespace System.Management.Automation.Language | |
| using namespace System.Collections.Generic | |
| using namespace System.Reflection | |
| # The current contents of the psm1 file would go here, including dot sourcing the class definition | |
| # files normally and exporting module members. | |
| # The rest can most likely be loaded into a function but I haven't tested it yet. It could also | |
| # use some cleaning up. | |
| $usingStatements = [List[UsingStatementAst]]::new() |
| <# | |
| Simple script that forces all static methods of types made | |
| with PowerShell to be bound to the current runspace. If you | |
| are getting NullReference exceptions every now and then, this | |
| might fix it. | |
| I put this in my profile as a temporary workaround, I do not | |
| recommend adding this to a module. It uses a large amount of | |
| reflection and could be unpredictable. | |
| #> |
| import { EventEmitter } from 'events' | |
| var clr = require('clr'); | |
| var namespaces = clr.init({ assemblies: [ 'System.Management.Automation' ], global: false }); | |
| export function forEachClr (collection: any, callback: (item: any) => any) { | |
| let enumerator = collection.GetEnumerator(); | |
| while (enumerator.MoveNext()) callback(enumerator.Current) | |
| } |
| # This should be included in SQL server if you have it installed, but I don't on this machine. | |
| $package = Find-Package Microsoft.SqlServer.TransactSql.ScriptDom -Source https://www.nuget.org/api/v2 | |
| $package | Save-Package -Path $PWD | |
| $fileBaseName = $package.Name + '.' + $package.Version | |
| Rename-Item "$fileBaseName.nupkg" "$fileBaseName.zip" | |
| Expand-Archive "$fileBaseName.zip" | |
| Add-Type -Path $fileBaseName\lib\net40\Microsoft.SqlServer.TransactSql.ScriptDom.dll | |
| # Example from https://docs.microsoft.com/en-us/sql/t-sql/queries/select-examples-transact-sql | |
| $tSqlSample = @' |
| #requires -Version 5.1 -Module @{ModuleName = 'PSReadline'; RequiredVersion=1.2} | |
| function Invoke-CommandPalette { | |
| param( | |
| [System.Nullable[System.ConsoleKeyInfo]] $key, | |
| [object] $arg | |
| ) | |
| end { | |
| # Save the current buffer, cursor position, selection range and selection command count to | |
| # be restored after the command is found. |
| $typeDefinition = @' | |
| using System; | |
| using System.Management.Automation; | |
| using System.Reflection; | |
| namespace PSStateTree.Commands | |
| { | |
| [OutputType(typeof(StateTreeInfo))] | |
| [Cmdlet(VerbsCommon.Show, "PSStateTree")] | |
| public class ShowPSStateTreeCommand : PSCmdlet |
| function New-PowerShellApp { | |
| [CmdletBinding()] | |
| param([string]$FilePath, [string]$Script) | |
| end { | |
| $Script = $Script -replace '"', '""' | |
| Add-Type -OutputType WindowsApplication -OutputAssembly $FilePath -TypeDefinition @" | |
| using System.Management.Automation; | |
| namespace SilentPowerShell |