Skip to content

Instantly share code, notes, and snippets.

@Brar
Created March 21, 2023 09:02
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 Brar/08238afa3e2fad85ed5632783d566e5b to your computer and use it in GitHub Desktop.
Save Brar/08238afa3e2fad85ed5632783d566e5b to your computer and use it in GitHub Desktop.
My PowerShell profile
if ($host.Name -eq 'ConsoleHost')
{
Import-Module PSReadLine
Import-Module posh-git
Import-Module git-aliases -DisableNameChecking
Import-Module Terminal-Icons
# Oh My Posh configuration
$ohMyPoshTheme = Get-Item "$env:HOME/.ohMyPoshTheme.omp.json" -Force -ErrorAction Ignore
if (-not $ohMyPoshTheme) {
$ohMyPoshTheme = Get-Item "$env:HOMEDRIVE$env:HOMEPATH$([System.IO.Path]::DirectorySeparatorChar).ohMyPoshTheme.omp.json" -Force -ErrorAction Ignore
}
if (-not $ohMyPoshTheme) {
$ohMyPoshTheme = Get-Item "$env:POSH_THEMES_PATH/darkblood.omp.json" -ErrorAction Ignore
}
if (-not $ohMyPoshTheme) {
$ohMyPoshTheme = Get-Item "$(brew --prefix oh-my-posh)/themes/darkblood.omp.json" -ErrorAction Ignore
}
if ($ohMyPoshTheme) {
oh-my-posh init pwsh --config $ohMyPoshTheme.FullName | Invoke-Expression
}
else {
oh-my-posh init pwsh | 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', $_)
}
}
# dotnet suggest shell start
if (Get-Command "dotnet-suggest" -errorAction SilentlyContinue)
{
$availableToComplete = (dotnet-suggest list) | Out-String
$availableToCompleteArray = $availableToComplete.Split([Environment]::NewLine, [System.StringSplitOptions]::RemoveEmptyEntries)
Register-ArgumentCompleter -Native -CommandName $availableToCompleteArray -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
$fullpath = (Get-Command $commandAst.CommandElements[0]).Source
$arguments = $commandAst.Extent.ToString().Replace('"', '\"')
dotnet-suggest get -e $fullpath --position $cursorPosition -- "$arguments" | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
}
else
{
"Unable to provide System.CommandLine tab completion support unless the [dotnet-suggest] tool is first installed."
"See the following for tool installation: https://www.nuget.org/packages/dotnet-suggest"
}
$env:DOTNET_SUGGEST_SCRIPT_VERSION = "1.0.2"
# dotnet suggest script end
# Personal aliases
Set-Alias al Get-Git-Aliases
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment