Skip to content

Instantly share code, notes, and snippets.

@TylerLeonhardt
Last active May 7, 2019 02:45
Show Gist options
  • Save TylerLeonhardt/ac4a3a43000d7e0b4dc48637ace43276 to your computer and use it in GitHub Desktop.
Save TylerLeonhardt/ac4a3a43000d7e0b4dc48637ace43276 to your computer and use it in GitHub Desktop.
PowerShell profile on macOS with posh-git and oh-my-posh.
$env:PATH = '/usr/local/bin:/usr/local/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Xamarin Workbooks.app/Contents/SharedSupport/path-bin:' + $env:PATH
function Update-PowerShellDaily {
iex "& { $(irm 'https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.ps1') } -daily"
}
$global:PostPromptHook = {
[Environment]::CurrentDirectory = $PWD.Path
}
Import-Module posh-git
Import-Module oh-my-posh
$ThemeSettings.MyThemesLocation = "~/.config/powershell/oh-my-posh/Themes"
Set-Theme Sorin-NL
Set-PSReadLineKeyHandler -Chord Alt+Enter -Function AddLine
Set-PSReadLineOption -ContinuationPrompt " "
# irm https://themtn.azurewebsites.net
#requires -Version 2 -Modules posh-git
function Write-Theme {
param(
[bool]
$lastCommandFailed,
[string]
$with
)
#check the last command state and indicate if failed
If ($lastCommandFailed) {
$prompt = Write-Prompt -Object "$($sl.PromptSymbols.FailedCommandSymbol) " -ForegroundColor $sl.Colors.CommandFailedIconForegroundColor
}
#check for elevated prompt
If (Test-Administrator) {
$prompt += Write-Prompt -Object "$($sl.PromptSymbols.ElevatedSymbol) " -ForegroundColor $sl.Colors.AdminIconForegroundColor
}
if ($PSVersionTable.GitCommitId.Length -gt 20) {
$prompt += Write-Prompt -Object '[DEV] ' -ForegroundColor $sl.Colors.CommandFailedIconForegroundColor
}
$user = [System.Environment]::UserName
if (Test-NotDefaultUser($user)) {
$prompt += Write-Prompt -Object "`e[1m$user`e[0m " -ForegroundColor $sl.Colors.PromptForegroundColor
}
# Writes the path
$prompt += Write-Prompt -Object "$(Get-FullPath -dir $pwd) " -ForegroundColor $sl.Colors.DriveForegroundColor
$status = Get-VCSStatus
if ($status) {
$themeInfo = Get-VcsInfo -status ($status)
$prompt += Write-Prompt -Object "git:" -ForegroundColor $sl.Colors.PromptForegroundColor
$prompt += Write-Prompt -Object "$($themeInfo.VcInfo) " -ForegroundColor $themeInfo.BackgroundColor
}
# write virtualenv
if (Test-VirtualEnv) {
$prompt += Write-Prompt -Object 'env:' -ForegroundColor $sl.Colors.PromptForegroundColor
$prompt += Write-Prompt -Object "$(Get-VirtualEnvName) " -ForegroundColor $themeInfo.VirtualEnvForegroundColor
}
if ($with) {
$prompt += Write-Prompt -Object "$($with.ToUpper()) " -BackgroundColor $sl.Colors.WithBackgroundColor -ForegroundColor $sl.Colors.WithForegroundColor
}
$prompt += Set-Newline
# Writes the postfixes to the prompt
$prompt += Write-Prompt -Object $sl.PromptSymbols.PromptIndicator -ForegroundColor $sl.Colors.CommandFailedIconForegroundColor
$prompt += Write-Prompt -Object $sl.PromptSymbols.PromptIndicator -ForegroundColor $sl.Colors.AdminIconForegroundColor
$prompt += Write-Prompt -Object $sl.PromptSymbols.PromptIndicator -ForegroundColor $sl.Colors.GitNoLocalChangesAndAheadColor
$prompt += ' '
$prompt
if($global:PostPromptHook) {
. $global:PostPromptHook
}
}
$sl = $global:ThemeSettings #local settings
$sl.PromptSymbols.PromptIndicator = [char]::ConvertFromUtf32(0x276F)
$sl.Colors.PromptForegroundColor = [ConsoleColor]::White
$sl.Colors.PromptSymbolColor = [ConsoleColor]::White
$sl.Colors.PromptHighlightColor = [ConsoleColor]::DarkBlue
$sl.Colors.WithForegroundColor = [ConsoleColor]::DarkRed
$sl.Colors.WithBackgroundColor = [ConsoleColor]::Magenta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment