# Enable Git completions & prompt. Import-Module Posh-Git $GitPromptSettings.EnableFileStatus = $false $GitPromptSettings.DefaultPromptPath = "" $GitPromptSettings.DefaultPromptPrefix.Text = "" $GitPromptSettings.DefaultPromptSuffix.Text = "" $GitPromptSettings.BeforeStatus = "" $GitPromptSettings.AfterStatus = "" # Enable Scoop completions. if (Get-Command scoop.ps1 -ErrorAction SilentlyContinue) { Import-Module "$($(Get-Item $(Get-Command scoop.ps1).Path).Directory.Parent.FullName)\modules\scoop-completion" } # Enable Chocolatey completions. Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" # Enable op completions. if (Test-Path "$env:LOCALAPPDATA\1Password\cli\opProfile.psm1") { Import-Module "$env:LOCALAPPDATA\1Password\cli\opProfile.psm1" } # Enable gh completions. if (Get-Command "gh" -ErrorAction SilentlyContinue) { Invoke-Expression -Command $(gh completion -s powershell | Out-String) } # Customize PowerShell prompt. function Prompt { $exitCode = $LastExitCode # Line one Get-Date -Format "HH:mm:ss " | Write-Host -ForegroundColor DarkGray -NoNewline $location = (Get-Location).Path if ($location.StartsWith($env:USERPROFILE)) { $location = $location.Replace($env:USERPROFILE, "~") } $location | Write-Host -ForegroundColor DarkCyan -NoNewline if ($exitCode -ne 0) { " $exitCode" | Write-Host -ForegroundColor DarkRed -NoNewline } & $GitPromptScriptBlock | Write-Host -NoNewline Write-Host # Line two $identity = [Security.Principal.WindowsIdentity]::GetCurrent() $principal = [Security.Principal.WindowsPrincipal] $identity $adminRole = [Security.Principal.WindowsBuiltInRole]::Administrator $userName = $Env:USERNAME.ToLower() if($principal.IsInRole($adminRole)) { $userName | Write-Host -ForegroundColor DarkRed -NoNewline } else { $userName | Write-Host -ForegroundColor DarkGreen -NoNewline } return ' ' } # Set UTF-8 as the character set for pipes and output objects. # https://gist.github.com/xoner/4671514 $OutputEncoding = New-Object -typename System.Text.UTF8Encoding [Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8 # Enable Vi line editing mode. Set-PSReadLineOption -BellStyle None -EditMode Vi # Make C-w backward delete a word. Set-PSReadLineKeyHandler -Chord Ctrl+w -Function BackwardDeleteWord # Make C-[ escape insert mode. # https://github.com/PowerShell/PSReadLine/issues/906#issuecomment-916847040 Set-PSReadLineKeyHandler -Chord 'Ctrl+Oem4' -Function ViCommandMode # Enable menu style tab completions. https://stackoverflow.com/a/37715242 Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete # Autosuggestion bindings for PSReadLine 2.1.0+ Set-PSReadLineKeyHandler -Chord "Ctrl+p" -Function ForwardChar Set-PSReadLineKeyHandler -Chord "Ctrl+o" -Function ForwardWord # Use grey but not italic for autosuggestion highlights Set-PSReadLineOption -Colors @{ InlinePrediction = "$([char]0x1b)[38;5;238m" } # Change cursor shape based on what Vi mode the line editor is in. # Tested and works with PowerShell 5.1 # NOTE: Requires: Install-Module PsReadline -Scope CurrentUser -Force # TODO: This doesn't handle all cases well. For example when exiting terminal # nvim in a PowerShell session the cursor is a block while in insert mode. function OnViModeChange { if ($args[0] -eq 'Command') { # Set the cursor to non-blinking block. Write-Host -NoNewLine "$([char]0x1b)[2 q" } else { # Set the cursor to non-blinking line. Write-Host -NoNewLine "$([char]0x1b)[6 q" } } Set-PSReadLineOption -ViModeIndicator Script -ViModeChangeHandler $Function:OnViModeChange # And set the cursor to a non-blinking line on profile load. Write-Host -NoNewLine "$([char]0x1b)[6 q" # Remove these aliases to PowerShell builtins which clobber the actaul exes. Remove-Item alias:curl Remove-Item alias:wget # Set environment variables # TODO: Wrap Enter-VsDevShell to also set these? if ((Get-Command cmake.exe -ErrorAction SilentlyContinue).Source) { $env:CMAKE_GENERATOR = 'Ninja' $env:CMAKE_C_COMPILER_LAUNCHER = 'cmake.exe' $env:CMAKE_CXX_COMPILER_LAUNCHER = 'cmake.exe' }