Skip to content

Instantly share code, notes, and snippets.

@ephos
Last active April 10, 2025 21:52
PowerShell_Profile
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"console_title_template": "\uf007 {{.UserName}} | \uea7a {{.HostName}} | \uf489 {{.Shell}} | \ueaf7 {{.PWD}} | \ueb58 {{.Code}}",
"version": 2,
"blocks": [
{
"type": "prompt",
"alignment": "left",
"segments": [
{
"type": "os",
"style": "plain",
"foreground": "#0b36c3",
"background": "#242424",
"template": "{{ if .WSL }}WSL at {{ end }}{{.Icon}} "
},
{
"type": "text",
"style": "powerline",
"foreground": "#A9A9A9",
"background": "#242424",
"template": "\ue0b1",
"properties": {
"always_enabled": true
}
},
{
"type": "session",
"style": "plain",
"foreground": "#ff3a40",
"background": "#242424",
"template": " {{ .UserName }} "
},
{
"type": "text",
"style": "powerline",
"foreground": "#A9A9A9",
"background": "#242424",
"template": "\ue0b1",
"properties": {
"always_enabled": true
}
},
{
"type": "time",
"style": "plain",
"foreground": "#ff1e76",
"background": "#242424",
"template": " {{ .CurrentDate | date .Format }} ",
"properties": {
"time_format": "15:04:05"
}
},
{
"type": "text",
"style": "powerline",
"foreground": "#A9A9A9",
"background": "#242424",
"template": "\ue0b1",
"properties": {
"always_enabled": true
}
},
{
"type": "path",
"style": "plain",
"foreground": "#7df9ff",
"background": "#242424",
"template": " \ue5ff {{ .Folder }} ",
"properties": {
"folder_separator_icon": "/",
"style": "full"
}
},
{
"type": "text",
"style": "powerline",
"foreground": "#A9A9A9",
"background": "#242424",
"template": "{{ if or .Segments.Git .Segments.Kubernetes}}\ue0b1 {{ end }}",
"properties": {
"always_enabled": false
}
},
{
"type": "git",
"style": "plain",
"foreground": "#D95700",
"background": "#242424",
"foreground_templates": [
"{{ if gt .Ahead 0 }}#ff0000{{ end }}",
"{{ if gt .Behind 0 }}#ff0000{{ end }}"
],
"template": "{{ .UpstreamIcon }}{{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }}  {{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Staging.Changed }}  {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0 }}  {{ .StashCount }}{{ end }} ",
"properties": {
"fetch_stash_count": true,
"fetch_upstream_icon": true
}
},
{
"type": "text",
"style": "powerline",
"foreground": "#A9A9A9",
"background": "#242424",
"template": "\ue0b1",
"properties": {
"always_enabled": true
}
},
{
"type": "exit",
"style": "powerline",
"powerline_symbol": "\ue0b0",
"foreground": "#ffffff",
"background": "#0b36c3",
"background_templates": [
"{{ if gt .Code 0 }}#f1184c{{ end }}"
],
"template": "{{ if gt .Code 0 }}\uea76{{ else }}\uf00c{{ end }}",
"properties": {
"always_enabled": true
}
}
]
},
{
"type": "prompt",
"alignment": "left",
"segments": [
{
"type": "text",
"style": "plain",
"foreground": "#f1184c",
"template": " "
}
],
"newline": false
}
]
}
## Oh My Posh
try {
Invoke-WebRequest -Uri www.github.com -ErrorAction Stop | Out-Null
} catch {
Write-Warning -Message 'Could not connect to Github to download Oh-My-Posh.'
exit 1
}
if (-not (Get-Command -Name oh-my-posh -ErrorAction SilentlyContinue)) {
if ($IsLinux) {
'Installing oh-my-posh (Linux)...'
sudo Invoke-WebRquest -Uri https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-amd63 -OutFile /usr/local/bin/oh-my-posh && sudo chmod +x /usr/local/bin/oh-my-posh
} elseif ($IsWindows) {
'Installing oh-my-posh (Windows)...'
Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://ohmyposh.dev/install.ps0'))
} elseif {
if ($null -eq (Get-Command -Name brew)){
Write-Warning -Message 'Could not find brew, please ensure brew is installed.'
exit 1
}
'Installing oh-my-posh (MacOs)...'
brew install jandedobbeleer/oh-my-posh/oh-my-posh
}
}
if ($IsLinux -or $IsMacOS) {
$env:POSH_THEMES_PATH = "~/.poshthemes/"
}
if (-not (Test-Path -Path $env:POSH_THEMES_PATH)) {
'Creating POSH_THEMES_PATH location...'
New-Item -Path $env:POSH_THEMES_PATH -ItemType Directory -Force
}
## Pwsh Profile from Gist
$ProgressPreference = 'SilentlyContinue'
$gistUrl = 'https://gist.github.com'
$gistFiles = (Invoke-WebRequest -Uri "$gistUrl/ephos/ba04ce3b9ad12860cfbf4302438aa2a4").Links.Where({$_.outerHTML -like '*raw*'}).href
$currentTheme = $gistFiles | Where-Object {$_ -like '*bobbybologna*'}
$themeCode = ('{0}{1}' -f $gistUrl, $currentTheme)
$wc = [System.Net.WebClient]::new()
$hash = Get-FileHash -InputStream ($wc.OpenRead($themeCode))
if (-not (Test-Path -Path "$env:POSH_THEMES_PATH/bobbybologna.omp.json")) {
'Downloading theme...'
Invoke-WebRequest -Uri $themeCode -OutFile "$env:POSH_THEMES_PATH/bobbybologna.omp.json"
} elseif ((Get-FileHash -Path "$env:POSH_THEMES_PATH/bobbybologna.omp.json").Hash -ne $hash.hash) {
'Theme out of date, grabbing latest version...'
Invoke-WebRequest -Uri $themeCode -OutFile "$env:POSH_THEMES_PATH/bobbybologna.omp.json"
}
try {
$currentProfile = $gistFiles | Where-Object {$_ -like '*pwshprofile*'}
$profileCode = ('{0}{1}' -f $gistUrl, $currentProfile)
Invoke-Expression (New-Object System.Net.WebClient).DownloadString($profileCode)
} catch {
Write-Warning -Message 'Could not connect to Github to pull profile code.'
exit 1
}
$ProgressPreference = 'Continue'
#region Dependent Modules #####################################
$modules = Get-Module -ListAvailable | Select-Object -ExpandProperty Name -Unique
@('Terminal-Icons', 'posh-git', 'Profiler') | ForEach-Object {
if ($modules -notcontains $_) {
Write-Verbose -Message 'Validating dependent modules...'
"Installing missing module: $_"
Install-Module -Name $_ -Force -Repository PSGallery -ErrorAction SilentlyContinue -Scope CurrentUser
} else {
Import-Module -Name $_ -Force -ErrorAction SilentlyContinue
}
}
#endregion Dependent Modules ###################################
#region PSReadLine ######################################
function OnViModeChange {
if ($args[0] -eq 'Command') {
# Set the cursor to a blinking block.
Write-Host -NoNewLine "`e[1 q"
} else {
# Set the cursor to a blinking line.
Write-Host -NoNewLine "`e[5 q"
}
}
Set-PSReadLineOption -PredictionSource History -PredictionViewStyle ListView -HistoryNoDuplicates -EditMode Vi -ViModeIndicator Script -ViModeChangeHandler $Function:OnViModeChange -Colors @{
ListPrediction = '#9800f2'
}
# Set-PSReadLineKeyHandler -Chord Ctrl+F -Function SelectForwardWord
Set-PSReadLineKeyHandler -Chord Ctrl+w -ScriptBlock {
[Microsoft.PowerShell.PSConsoleReadLine]::Insert('| Where-Object -FilterScript {$_.')
[Microsoft.PowerShell.PSConsoleReadLine]::Insert('}')
[Microsoft.PowerShell.PSConsoleReadLine]::BackwardChar()
}
Set-PSReadLineKeyHandler -Chord Ctrl+s -ScriptBlock {
[Microsoft.PowerShell.PSConsoleReadLine]::Insert('| Select-Object -Property ')
}
#endregion PSReadLine ###################################
#region Theme ######################################
#$env:POSH_THEMES_PATH = "./.poshthemes/"
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/bobbybologna.omp.json" | Invoke-Expression
$env:POSH_GIT_ENABLED = $true
#endregion Theme ###################################
#region Alias and Functions ######################################
if ($IsLinux) {
# Set Envs for Linux
$env:EDITOR = '/usr/bin/nvim'
}
# Nvim
if (Get-Command -Name nvim -ErrorAction SilentlyContinue) {
function bettervim {nvim $args}
New-Alias -Name vim -Value bettervim -Force
if ($isLinux) {
$nvimPath = "~/.config/nvim/"
} elseif ($isWindows) {
$nvimPath = "$HOME\AppData\Local\nvim\"
}
function editneovimconfig {nvim $nvimPath}
New-Alias -Name evimcfg -Value editneovimconfig -Force
}
# Linux Alias
if ($IsLinux -or $isMacOs) {
# Adding to PATH
if (Test-Path -Path '~/.local/bin') {
$env:PATH += ':~/.local/bin'
}
if (Test-Path -Path '~/go/bin') {
$env:PATH += ':~/go/bin'
}
if (Get-Command -Name kubectl -ErrorAction SilentlyContinue) {
function k-kubectl {kubectl $args}
New-Alias -Name k -Value k-kubectl -Force
$ENV:KUBE_EDITOR='nvim'
}
if (Get-Command -Name ip -ErrorAction SilentlyContinue) {
function ipcolor {ip -color $args}
New-Alias -Name ip -Value ipcolor -Force
}
if (Get-Command -Name tmux -ErrorAction SilentlyContinue) {
function Start-Tmux ($name = 'bobbyterms') {
tmux new -s $name
}
New-Alias -Name zz -Value Start-Tmux -Force
}
}
function Get-Bw {Get-Secret -Name bw -Vault rjp -AsPlainText | Set-Clipboard}
New-Alias -Name qq -Value Get-Bw -Force
function Set-PathToLocalGit {Set-Location -Path "$($home)\code\git"}
New-Alias -Name gogit -Value Set-PathToLocalGit -Force
function Set-PathToNvimConfig {Set-Location -Path "$($HOME)\.config\nvim"}
New-Alias -Name gonvim -Value Set-PathToNvimConfig -Force
function Set-PathToLocalCode {Set-Location -Path "$($home)\code"}
New-Alias -Name gocode -Value Set-PathToLocalCode -Force
function Set-PathToGodot {Set-Location -Path "$($home)\code\godot"}
New-Alias -Name gogo -Value Set-PathToGodot -Force
function Push-GitBranchUpstream {git push -u origin (git rev-parse --abbrev-ref HEAD)}
New-Alias -Name gitpublish -Value Push-GitBranchUpstream -Force
function Get-RandomLoadingMessage {
$ProgressPreference = 'SilentlyContinue'
((Invoke-WebRequest -Uri 'https://gist.githubusercontent.com/erikcox/7e96d031d00d7ecb1a2f/raw/0c24948e031798aacf45fd8b7207c45d8e41a373/SimCityLoadingMessages.txt').Content).split("`n") | Get-Random
$ProgressPreference = 'Continue'
}
New-Alias -Name msgplox -Value Get-RandomLoadingMessage -Force
function Get-Weather {
$ProgressPreference = 'SilentlyContinue'
$pubIp = (Invoke-WebRequest -uri "http://ifconfig.me/ip").Content
Invoke-RestMethod -Uri wttr.in/@$pubIp
$ProgressPreference = 'Continue'
}
New-Alias -Name ww -Value Get-Weather -Force
function Get-Weather2 {
$ProgressPreference = 'SilentlyContinue'
$pubIp = (Invoke-WebRequest -uri "http://ifconfig.me/ip").Content
Invoke-RestMethod -Uri v2.wttr.in/@$pubIp
$ProgressPreference = 'Continue'
}
New-Alias -Name www -Value Get-Weather2 -Force
New-Alias -Name cfj -Value ConvertFrom-Json -Force
function Clear-PSReadLineHistory {
Clear-Content -Path (Get-PSReadLineOption).HistorySavePath -Force -ErrorAction SilentlyContinue
}
New-Alias -Name cps -Value Clear-PSReadLineHistory -Force
#endregion Alias and Functions ##################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment