Skip to content

Instantly share code, notes, and snippets.

View jdharmon's full-sized avatar

Jason Harmon jdharmon

  • PROSOFT
  • Virginia Beach, VA
View GitHub Profile
@jdharmon
jdharmon / Set-RepoLocation.ps1
Last active April 29, 2026 13:04
Quickly navigate into local repository subdirectories with tab completion for the repository names.
$env:REPOS_PATH='C:\Source\Repos'
function Set-RepoLocation ($name) {
Set-Location $(Join-Path $env:REPOS_PATH $name)
}
Set-Alias cdr Set-RepoLocation
Register-ArgumentCompleter -CommandName @('Set-RepoLocation', 'cdr') -ParameterName 'name' -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
@jdharmon
jdharmon / Decode-Jwt.ps1
Last active February 18, 2026 16:38
Decode JSON Web Token (JWT) payload
function Decode-Jwt($token) {
$payload = $token.Split('.')[1]
switch ($payload.Length % 4) {
2 { $payload += '==' }
3 { $payload += '=' }
}
$json = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($payload))
$json | ConvertFrom-Json | ConvertTo-Json
}
@jdharmon
jdharmon / posh-git.zsh-theme
Last active January 26, 2025 13:09
Oh My Zsh theme that mimics the behavior of posh-git
# Colors
local RED="%F{red}"
local GREEN="%F{green}"
local BLUE="%F{blue}"
local YELLOW="%F{yellow}"
local MAGENTA="%F{magenta}"
local CYAN="%F{cyan}"
local RESET="%f"
# Symbols
@jdharmon
jdharmon / Git-Prompt.ps1
Last active April 2, 2025 18:21
One-page PowerShell Git Prompt. Alternative to posh-git.
# Add to PowerShell $PROFILE
function Get-GitPrompt {
$inGitRepo = [bool](git rev-parse --is-inside-work-tree 2>$null)
if (-not $inGitRepo) {
return
}
$branch = git branch --show-current
$status = git status --short --branch
function Set-WorkingDirectory($Path) {
if (-not $Path) {
$Path = "~"
}
if ((Resolve-Path $Path).Provider.Name -eq 'FileSystem') {
[System.IO.Directory]::SetCurrentDirectory($Path)
}
Set-Location $Path
}
private static void WaitForExitSignal()
{
using (var signal = new ManualResetEventSlim())
{
// Handle SIGTERM
AssemblyLoadContext.Default.Unloading += _ => signal.Set();
// Hadle SIGINT/Ctrl+C
Console.CancelKeyPress += (s, a) =>
{
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.IO;
using System.Runtime.Loader;
using System.Threading;
using System.Threading.Tasks;
namespace MyApp
@jdharmon
jdharmon / PSCommandCompletion.ps1
Last active November 28, 2023 21:07
PowerShell Kubectl & Helm Command Completion
# Setup
Install-Module -Name PSBashCompletions -Scope CurrentUser
$path = (mkdir (Join-Path (Split-Path -Parent $PROFILE) Completion)).FullName
((kubectl completion bash) -join "`n") | Set-Content -Encoding ASCII -NoNewline -Path $path/kubectl.sh
((helm completion bash) -join "`n") | Set-Content -Encoding ASCII -NoNewline -Path $path/helm.sh
# Profile
$completionPath = Join-Path (Split-Path -Parent $PROFILE) Completion
if (Test-Path $completionPath) {
Import-Module PSBashCompletions
@jdharmon
jdharmon / Watch-Command.ps1
Last active July 27, 2020 14:11
PowerShell watch
function Watch-Command {
[CmdletBinding()]
Param(
[Parameter(ValueFromPipeline, Mandatory)]
[object]
$ScriptBlock,
[int]
$Seconds = 2
)
@jdharmon
jdharmon / Join-Url.ps1
Created February 12, 2019 18:56
PowerShell Join-Url
function Join-Url([string[]]$parts) {
return ($parts | % { $_.Trim('/') } | ? { $_ }) -join '/'
}