This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Set-WorkingDirectory($Path) { | |
| if (-not $Path) { | |
| $Path = "~" | |
| } | |
| if ((Resolve-Path $Path).Provider.Name -eq 'FileSystem') { | |
| [System.IO.Directory]::SetCurrentDirectory($Path) | |
| } | |
| Set-Location $Path | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static void WaitForExitSignal() | |
| { | |
| using (var signal = new ManualResetEventSlim()) | |
| { | |
| // Handle SIGTERM | |
| AssemblyLoadContext.Default.Unloading += _ => signal.Set(); | |
| // Hadle SIGINT/Ctrl+C | |
| Console.CancelKeyPress += (s, a) => | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Watch-Command { | |
| [CmdletBinding()] | |
| Param( | |
| [Parameter(ValueFromPipeline, Mandatory)] | |
| [object] | |
| $ScriptBlock, | |
| [int] | |
| $Seconds = 2 | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Join-Url([string[]]$parts) { | |
| return ($parts | % { $_.Trim('/') } | ? { $_ }) -join '/' | |
| } |
NewerOlder