Skip to content

Instantly share code, notes, and snippets.

@thepaulmacca
Last active February 14, 2025 11:50
Show Gist options
  • Save thepaulmacca/2877c760f7fab966e4108e06eb44e2c9 to your computer and use it in GitHub Desktop.
Save thepaulmacca/2877c760f7fab966e4108e06eb44e2c9 to your computer and use it in GitHub Desktop.
PowerShell Profile
using namespace System.Management.Automation
using namespace System.Management.Automation.Language
if ($host.Name -eq 'ConsoleHost')
{
Import-Module PSReadLine
}
Import-Module posh-git
## Customize the prompt
function prompt {
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = [Security.Principal.WindowsPrincipal] $identity
$adminRole = [Security.Principal.WindowsBuiltInRole]::Administrator
$prefix = if (Test-Path variable:/PSDebugContext) { '[DBG]: ' } else { '' }
if ($principal.IsInRole($adminRole)) {
$prefix = "[ADMIN]:$prefix"
}
$body = 'PS ' + $PWD.path
$suffix = $(if ($NestedPromptLevel -ge 1) { '>>' }) + '> '
"${prefix}${body}${suffix}"
}
## Set PSReadLine options and keybindings
$PSROptions = @{
ContinuationPrompt = ' '
Colors = @{
Operator = $PSStyle.Foreground.Magenta
Parameter = $PSStyle.Foreground.Magenta
Selection = $PSStyle.Background.BrightBlack
InLinePrediction = $PSStyle.Foreground.BrightYellow + $PSStyle.Background.BrightBlack
}
}
Set-PSReadLineOption @PSROptions
Set-PSReadLineKeyHandler -Chord 'Ctrl+f' -Function ForwardWord
Set-PSReadLineKeyHandler -Chord 'Enter' -Function ValidateAndAcceptLine
## Add argument completer for the dotnet CLI tool
$scriptblock = {
param($wordToComplete, $commandAst, $cursorPosition)
dotnet complete --position $cursorPosition $commandAst.ToString() |
ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock $scriptblock
# Helm
helm completion powershell | Out-String | Invoke-Expression
# Kubernetes
Set-Alias -Name k -Value kubectl
kubectl completion powershell | Out-String | Invoke-Expression
Register-ArgumentCompleter -CommandName k -ScriptBlock $__kubectlCompleterBlock
# Starship
function Invoke-Starship-PreCommand {
$host.ui.Write("🚀")
}
Invoke-Expression (&starship init powershell)
# Task
Invoke-Expression (&task --completion powershell | Out-String)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment