Skip to content

Instantly share code, notes, and snippets.

@ephos
Last active June 3, 2024 15:03
Show Gist options
  • Save ephos/ba04ce3b9ad12860cfbf4302438aa2a4 to your computer and use it in GitHub Desktop.
Save ephos/ba04ce3b9ad12860cfbf4302438aa2a4 to your computer and use it in GitHub Desktop.
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 {
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-amd64 -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.ps1'))
}
}
} catch {
Write-Warning -Message 'Could not connect to Github to download Oh-My-Posh.'
exit 1
}
if ($IsLinux) {
$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 Golang ######################################
#Set go workspace.
#if (Get-Command -Name go -ErrorAction SilentlyContinue) {
#
# # Set the GOPATH
# $goPath = ((go env).Where({$_ -clike '*GOPATH=*'}) -split ('=') | Select-Object -Last 1 -Property @{n='GoPath';e={$_.replace('"','')}}).GoPath
# $env:GOPATH = $goPath
#
# if (-not (Test-Path -Path $env:GOPATH -ErrorAction SilentlyContinue)) {
# Write-Output -InputObject 'GOPATH is not setup, creating directory structure now.'
# New-Item -ItemType Directory -Path $env:GOPATH -ErrorAction SilentlyContinue
# New-Item -ItemType Directory -Path $env:GOPATH\bin\ -ErrorAction SilentlyContinue
# New-Item -ItemType Directory -Path $env:GOPATH\src\ -ErrorAction SilentlyContinue
# New-Item -ItemType Directory -Path $env:GOPATH\pkg\ -ErrorAction SilentlyContinue
# }
#
# # Add Go user bins to PATH
# $env:PATH += [IO.Path]::PathSeparator + "~/go/bin"
#
#} else {
# Write-Warning -Message "Go Language not installed, skipping."
#}
#endregion Golang ###################################
#region Alias and Functions ######################################
if ($IsLinux) {
if (Get-Command -Name kitty -ErrorAction SilentlyContinue) {
$env:TERM='kitty'
}
# setxkbmap -option caps:swapescape
}
# Nvim
if (Get-Command -Name nvim -ErrorAction SilentlyContinue) {
function bettervim {nvim $args}
New-Alias -Name vim -Value bettervim -Force
function editneovimconfig {nvim $HOME\AppData\Local\nvim\}
New-Alias -Name evimcfg -Value editneovimconfig -Force
}
# Linux Alias
if ($IsLinux -or $isMacOs) {
if (Get-Command -Name lsd -ErrorAction SilentlyContinue) {
function ls-modunix {lsd -l $args}
New-Alias -Name ls -Value ls-modunix -Force
} else {
function ls-basic {ls --color $args}
New-Alias -Name ls -Value ls-basic -Force
}
if (Get-Command -Name batcat -ErrorAction SilentlyContinue) {
function cat-modunixubuntu {batcat $args}
New-Alias -Name cat -Value cat-modunixubuntu -Force
}
if (Get-Command -Name bat -ErrorAction SilentlyContinue) {
function cat-modunix {bat $args}
New-Alias -Name cat -Value cat-modunix -Force
}
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-Process -Id $PID).Parent.ProcessName) {
function ssh-kitty {kitty +kitten ssh $args}
New-Alias -Name ssh -Value ssh-kitty -Force
}
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
}
}
# Adding to PATH
if (Test-Path -Path '~/.local/bin') {
$env:PATH += ':~/.local/bin'
}
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 status -sb).replace('## ', '')[0])}
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
if (-not $IsWindows) {
function config([string]$gitflag) {
/usr/bin/git $gitflag --git-dir=$HOME/.cfg/.git --work-tree=$HOME
}
}
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