Skip to content

Instantly share code, notes, and snippets.

@tonesandtones
Last active May 23, 2025 01:29
Show Gist options
  • Save tonesandtones/ea12d8ec8ec0e7cda1a07a8ace512235 to your computer and use it in GitHub Desktop.
Save tonesandtones/ea12d8ec8ec0e7cda1a07a8ace512235 to your computer and use it in GitHub Desktop.
Tones' Oh-my-Posh PowerShell profile
#Tones' Oh-My-Posh Powershell profile
# One time setup: https://ohmyposh.dev/docs/installation/windows (or your OS of choice)
# Install-Module -Name Terminal-Icons -Repository PSGallery
Import-Module Terminal-Icons
oh-my-posh init pwsh --config "~/posh/.posh.tones.honukaiterm.json" | Invoke-Expression
# PowerShell parameter completion shim for the dotnet CLI
Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock {
param($commandName, $wordToComplete, $cursorPosition)
dotnet complete --position $cursorPosition "$wordToComplete" | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
[Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new()
$Local:word = $wordToComplete.Replace('"', '""')
$Local:ast = $commandAst.ToString().Replace('"', '""')
winget complete --word="$Local:word" --commandline "$Local:ast" --position $cursorPosition | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
Register-ArgumentCompleter -Native -CommandName nuke -ScriptBlock {
param($commandName, $wordToComplete, $cursorPosition)
nuke :complete "$wordToComplete" | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
# Based on https://superuser.com/a/1598420
# Compared to original SO answer, changed [string]$command parameter to a [scriptblock]
# to get shell completion for the command you want to watch
function Watch-Command {
[CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact='High')]
param (
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True)]
[scriptblock]$command,
[Parameter(Mandatory=$False,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True)]
[int]$interval = 2
)
process {
$cmd = [scriptblock]::Create($command);
While($True) {
$output = $cmd.Invoke();
cls;
Write-Host "Command: " $command;
Write-Host ($output | Out-String);
sleep $interval;
}
}
}
Set-Alias -Name watch -Value Watch-Command
@tonesandtones
Copy link
Author

tonesandtones commented May 23, 2025

Added a powershell equivalent to watch. Note, you have the command in script block curlies { }.

Watch-Command {<command>}

watch { <command> }

@tonesandtones
Copy link
Author

> Get-Alias watch
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           watch -> Watch-Command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment