Skip to content

Instantly share code, notes, and snippets.

@rkeithhill
rkeithhill / ResetColors.ps1
Created January 11, 2015 02:36
Resets the console background and foreground colors to their startup values
# Certains console exes have a tendency to bork the console colors - looking at you
# MSBuild.exe. Either copy/paste this into your profile.ps1 file or dot source it.
$script:origBgColor = $host.ui.rawui.BackgroundColor
$script:origFgColor = $host.ui.rawui.ForegroundColor
function Reset-Colors
{
$host.ui.rawui.BackgroundColor = $origBgColor
$host.ui.rawui.ForegroundColor = $origFgColor
}
@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 / 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 / build.ps1
Last active April 2, 2020 15:33
PSake build script for publishing PowerShell modules
# This is a PSake script that supports the following tasks:
# clean, build, test and publish. The default task is build.
#
# The publish task uses the Publish-Module command to publish
# to either the PowerShell Gallery (the default) or you can change
# the $Repository property to the name of an alternate repository.
#
# The test task invokes Pester to run any Pester tests in your
# workspace folder. Name your test scripts <TestName>.Tests.ps1
# and Pester will find and run the tests contained in the files.
@rkeithhill
rkeithhill / Optimize-PSReadlineHistory.ps1
Last active August 14, 2024 00:33
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 / 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.
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 / gitconfig.txt
Last active November 29, 2019 18:35
Config file for Git
# More gitconfig goodness here - https://gist.github.com/tdd/470582
git config --global user.name "Keith Hill"
git config --global user.email <email here>
git config --global core.editor '\"C:\Program Files (x86)\Microsoft VS Code\bin\code.cmd\" --new-window --wait'
git config --global core.autocrlf true
git config --global pull.ff only
git config --global pull.rebase true
git config --global rebase.autoStash true
@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" },
@rkeithhill
rkeithhill / VSCode-settings.json
Last active October 30, 2024 13:33
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",