Skip to content

Instantly share code, notes, and snippets.

@rkeithhill
rkeithhill / Optimize-PSReadlineHistory.ps1
Last active April 19, 2024 20:00
Removes duplicate and optionally short commands from your PSReadline history file
<#
.SYNOPSIS
Optimizes your PSReadline history save file.
.DESCRIPTION
Optimizes your PSReadline history save file by removing duplicate
entries and optionally removing commands that are not longer than
a minimum length
.EXAMPLE
C:\PS> Optimize-PSReadlineHistory
Removes all the duplicate commands.
@rkeithhill
rkeithhill / powershell.json
Last active February 23, 2024 23:18
PowerShell snippets file for Visual Studio Code - place in your ~\AppData\Roaming\Code\User\Snippets directory
{
"Condition statement": {
"prefix": "cond",
"body": [
"$1 { $0; break }"
],
"description": "Switch condition statement"
},
"Condition single quoted string statement": {
"prefix": "condsqstr",
@rkeithhill
rkeithhill / PSReadLine_config.ps1
Last active December 10, 2023 03:03
Config file for PSReadLine
# Other hosts (ISE, ConEmu) don't always work as well with PSReadLine.
# Also, if PS is run with -Command, PSRL loading is suppressed.
$psrlMod = Get-Module PSReadLine
if (($null -eq $psrlMod) -or ($host.Name -eq 'Windows PowerShell ISE Host')) {
return
}
elseif ($psrlMod.Version.Major -lt 2) {
throw "PSReadLine 1.x installed or not imported, import PSRL or ugprade to at least 2.x."
}
@rkeithhill
rkeithhill / posh-git_config.ps1
Last active February 26, 2023 19:27
Config file for posh-git.
# Import Posh-Git and configure Git prompt
Import-Module posh-git
#Import-Module ~\GitHub\dahlbyk\posh-git\src\posh-git.psd1
#Import-Module ~\GitHub\dahlbyk\posh-git\out\posh-git\1.0.0\posh-git.psd1
# Windows PowerShell doesn't parse `e or `u escape sequences in DQ strings. I added that support to the PS parser in 6.0
if ($PSVersionTable.PSVersion.Major -lt 6) {
$global:GitPromptSettings.WindowTitle = {
param($GitStatus, [bool]$IsAdmin)
$wingetCompleter = {
param($wordToComplete, $commandAst, $cursorPosition)
$tokens = $commandAst.Extent.Text.Trim() -split '\s+'
$completions = switch ($tokens[1]) {
'install' { "-q","-m","-v","-s","-e","-i","-h","-o","-l",
"--query","--manifest","--id","--name","--moniker","--version","--source","--exact","--interactive",
"--silent","--log","--override","--location","--help"; break }
'search' { "-q","-s","-n","-e","-?",
"--query","--id","--name","--moniker","--tag","--command","--source","--count","--exact","--help"
if (($PSVersionTable.PSVersion.Major -le 5) -or $IsWindows) {
Set-Alias nano 'C:\Program Files\Git\usr\bin\nano.exe'
Set-Alias vim 'C:\Program Files\Git\usr\bin\vim.exe'
}
# Edition/platform specific configuration
if ($IsWindows) {
$env:PAGER = 'less -Ps"Page %db?B of %D:.\. Press h for help or Q to quit\."'
if ($PSVersionTable.PSEdition -eq 'Desktop') {
$PSDefaultParameterValues['Get-Help:Full'] = $true
@rkeithhill
rkeithhill / ConfigureConsoleSettings.ps1
Last active January 25, 2021 22:40
Configures the PowerShell console settings (colors, fonts, buffer size, etc).
<#
.SYNOPSIS
Sets the console settings to the specified values and color theme.
.DESCRIPTION
Sets the console settings to the specified values and color theme.
.EXAMPLE
C:\PS> Configure-ConsoleSettings -Theme ConEmu -WindowSize 120,50 `
-FontFace Consolas -FontSize 12
Sets the colors to those used in ConEmu and sets the font and window size.
@rkeithhill
rkeithhill / VSCode-settings.json
Last active January 14, 2021 12:46
My Visual Studio Code user settings
// Place your settings in this file to overwrite the default settings
{
"debug.toolBarLocation": "docked",
"diffEditor.ignoreTrimWhitespace": true,
"editor.codeLens": true,
"editor.detectIndentation": false,
"editor.dragAndDrop": false,
"editor.renderWhitespace": "none",
@rkeithhill
rkeithhill / settings.json
Last active November 21, 2020 22:39
Windows Terminal home profile
// This file was initially generated by Windows Terminal 0.11.1121.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
@rkeithhill
rkeithhill / VSCode-keybindings.json
Last active April 30, 2020 18:43
My Visual Studio Code customized keyboard shorcuts
// Place your key bindings in this file to overwrite the defaults
[
{ "key": "alt+n", "command": "explorer.newFile" },
{ "key": "alt+shift+s", "command": "PowerShell.InvokeRegisteredEditorCommand",
"args": { "commandName": "ConvertToSplatExpression" },
"when": "editorLangId == 'powershell'" },
{ "key": "ctrl+shift+q", "command": "workbench.action.toggleMaximizedPanel" },
{ "key": "ctrl+shift+s", "command": "workbench.action.files.saveAll" },
{ "key": "ctrl+shift+t", "command": "workbench.action.tasks.test" },
{ "key": "ctrl+alt+t", "command": "workbench.action.tasks.runTask" },