Skip to content

Instantly share code, notes, and snippets.

@NetzwergX
Last active August 4, 2022 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NetzwergX/032eaed6f99487ba277407ba2f456f07 to your computer and use it in GitHub Desktop.
Save NetzwergX/032eaed6f99487ba277407ba2f456f07 to your computer and use it in GitHub Desktop.
My PowerShell Profile -- includes oh-my-posh and auto completion for git, docker and dotnet and suggestions from history
# SETUP:
# Install-Module posh-git -Scope CurrentUser
# Install-Module Terminal-Icons -Scope CurrentUser
# winget install JanDeDobbeleer.OhMyPosh -s winget
# Install-Module DockerCompletion -Scope CurrentUser
# Install-Module -Name PSReadLine -Scope CurrentUser
# Install-Module oh-my-posh -Scope CurrentUser
# TODO: https://ohmyposh.dev/docs/migrating
[console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding
# 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', $_)
}
}
Import-Module Terminal-Icons
Import-Module posh-git # git autocpmpletion, c.f. https://github.com/dahlbyk/posh-git
Set-PoshPrompt -Theme ~/.oh-my-posh.omp.json
Import-Module DockerCompletion # completion for docker commands
Set-PSReadLineOption -PredictionSource History
# My POSIX-like `touch` utility
function Set-LastWriteTime
{
$file = $args[0]
if ($null -eq $file) {
Write-Error "Filename not specified." -ErrorAction:Stop
}
if (Test-Path $file)
{
(Get-ChildItem $file).LastWriteTime = Get-Date
}
else
{
Add-Content $file $null
}
}
New-Alias -Name touch Set-LastWriteTime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment