Skip to content

Instantly share code, notes, and snippets.

using namespace System
using namespace System.Linq
using namespace System.Collections
using namespace System.Collections.Generic
using namespace System.Management.Automation
using namespace System.Management.Automation.Language
using namespace System.Reflection
# Hey person reading this! Don't do this, alright? You'll have a bad time. ty
$parameters = @{
Key = 'F7'
BriefDescription = 'ShowMatchingHistoryOcgv'
LongDescription = 'Show Matching History using Out-ConsoleGridView'
ScriptBlock = {
param($key, $arg) # The arguments are ignored in this example
$line = $null
$cursor = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
$history = [Microsoft.PowerShell.PSConsoleReadLine]::GetHistoryItems().CommandLine | Select-Object -Unique
@jph00
jph00 / blog_test.ipynb
Created January 19, 2020 22:03
/nbs/blog_test.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Function CallbackWrapper {
param (
[string]$callbackScript,
[object]$param,
[int]$order
)
$callback = [ScriptBlock]::Create($callbackScript)
return [PSCustomObject]@{
Result = $callback.InvokeReturnAsIs($param)
Order = $order
@davebrny
davebrny / txt.wrap.ahk
Last active February 18, 2024 12:29
✏️ (autohotkey) - wrap selected text in *symbols*
/*
[wrap list]
( = (TXT)
`[ = [TXT]
{ = {TXT}
< = <TXT>
> = >TXT<
a = /`*TXT*`/
h = <!-- TXT -->

How to get @DevBlackOps Terminal-Icons module working in PowerShell on Windows

Note: since version 0.1.1 of the module this now works in Windows PowerShell or PowerShell Core.

  1. Download and install this version of Literation Mono Nerd Font which has been specifically fixed to be recognised as monospace on Windows:

https://github.com/haasosaurus/nerd-fonts/blob/regen-mono-font-fix/patched-fonts/LiberationMono/complete/Literation%20Mono%20Nerd%20Font%20Complete%20Mono%20Windows%20Compatible.ttf

(see this issue for more info: ryanoasis/nerd-fonts#269)

@grokk-it
grokk-it / PSANSI256.txt
Last active October 24, 2020 07:48
PowerShell ANSI 256-color chart
# 256-Color Foreground & Background Charts
$esc=$([char]27)
echo "`n$esc[1;4m256-Color Foreground & Background Charts$esc[0m"
foreach ($fgbg in 38,48) { # foreground/background switch
foreach ($color in 0..255) { # color range
#Display the colors
$field = "$color".PadLeft(4) # pad the chart boxes with spaces
Write-Host -NoNewLine "$esc[$fgbg;5;${color}m$field $esc[0m"
#Display 6 colors per line
if ( (($color+1)%6) -eq 4 ) { echo "`r" }
@Jaykul
Jaykul / About CommandNotFoundAction.md
Last active April 9, 2023 01:41
Helpfully handling Command Not Found in PowerShell

Helpfully handling Command Not Found in PowerShell

About CommandNotFoundAction

In PowerShell there is a callback ("Action") that is called when a command lookup fails through normal means. The purpose of this callback is to allow you to add your own command-resolution, and there are a lot of community hacks out there already:

Community Implementations

  • You could add support for new command types, like
@fearthecowboy
fearthecowboy / new-alias.ps1
Created February 1, 2019 00:48
A better new-alias for PowerShell
<#
.SYNOPSIS
Creates a new alias. Better than original New-Alias
.DESCRIPTION
Creates a new Function Alias. Unlike the original New-Alias, this will let you
create an alias that can be a command line or script, in a single command.
var searchterm='ACME Corporation'; //text to search for
//this is the decoded base64 string from the global search url
var stringToEncode = '{"componentDef":"forceSearch:search","attributes":{"term":"'+searchterm+'","scopeMap":{"resultsCmp":"forceSearch:resultsTopResults","label":"Top Results","type":"TOP_RESULTS","cacheable":"Y","id":"TOP_RESULTS","labelPlural":"Top Results"},"context":{"disableSpellCorrection":false,"SEARCH_ACTIVITY":{"term":1234567890}}},"state":{}}';
//convert to base64encode
var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(e){var t="";var n,r,i,s,o,u,a;var f=0;e=Base64._utf8_encode(e);while(f<e.length){n=e.charCodeAt(f++);r=e.charCodeAt(f++);i=e.charCodeAt(f++);s=n>>2;o=(n&3)<<4|r>>4;u=(r&15)<<2|i>>6;a=i&63;if(isNaN(r)){u=a=64}else if(isNaN(i)){a=64}t=t+this._keyStr.charAt(s)+this._keyStr.charAt(o)+this._keyStr.charAt(u)+this._keyStr.charAt(a)}return t},decode:function(e){var t="";var n,r,i;var s,o,u,a;var f=0;e=e.replace(/[^A-Za-