From 73ccf329640316f26305e6b0c8dc75956b370237 Mon Sep 17 00:00:00 2001 From: Alen Date: Wed, 13 Sep 2023 00:28:43 +0400 Subject: Add basic PowerShell profile --- .chezmoiignore | 6 ++ Documents/PowerShell/profile.ps1.tmpl | 1 + OneDrive/Documents/PowerShell/profile.ps1.tmpl | 1 + dot_alen.omp.yaml | 75 +++++++++++++++++++++++ dot_config/powershell/profile.ps1 | 85 ++++++++++++++++++++++++++ 5 files changed, 168 insertions(+) create mode 100644 Documents/PowerShell/profile.ps1.tmpl create mode 100644 OneDrive/Documents/PowerShell/profile.ps1.tmpl create mode 100644 dot_alen.omp.yaml create mode 100644 dot_config/powershell/profile.ps1 diff --git a/.chezmoiignore b/.chezmoiignore index 182b6ad..36e7889 100644 --- a/.chezmoiignore +++ b/.chezmoiignore @@ -20,3 +20,9 @@ # Ignore all shell scripts on Windows {{ if eq .chezmoi.os "windows" -}} /*.sh {{- end }} + +# Ignore correct powershell paths depending on OS +{{ if ne .chezmoi.os "windows" }} +/OneDrive/Documents/PowerShell/profile.ps1 +/Documents/PowerShell/profile.ps1 +{{ end }} diff --git a/Documents/PowerShell/profile.ps1.tmpl b/Documents/PowerShell/profile.ps1.tmpl new file mode 100644 index 0000000..f5b6dcf --- /dev/null +++ b/Documents/PowerShell/profile.ps1.tmpl @@ -0,0 +1 @@ +{{- include "dot_config/powershell/profile.ps1" -}} diff --git a/OneDrive/Documents/PowerShell/profile.ps1.tmpl b/OneDrive/Documents/PowerShell/profile.ps1.tmpl new file mode 100644 index 0000000..f5b6dcf --- /dev/null +++ b/OneDrive/Documents/PowerShell/profile.ps1.tmpl @@ -0,0 +1 @@ +{{- include "dot_config/powershell/profile.ps1" -}} diff --git a/dot_alen.omp.yaml b/dot_alen.omp.yaml new file mode 100644 index 0000000..2caef42 --- /dev/null +++ b/dot_alen.omp.yaml @@ -0,0 +1,75 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json +_anchors: + - <r  + - &rtl  +final_space: true +shell_integration: true +version: 2 +blocks: + - type: prompt + alignment: left + newline: true + segments: + - type: os + style: diamond + background: white + foreground: black + - type: root + style: powerline + powerline_symbol: *ltr + background: red + foreground: yellow + - type: path + style: powerline + powerline_symbol: *ltr + background: blue + foreground: white + - type: git + style: powerline + powerline_symbol: *ltr + background: green + foreground: black + - type: text + style: powerline + powerline_symbol: *ltr + - type: prompt + alignment: right + segments: + - type: executiontime + style: powerline + powerline_symbol: *rtl + invert_powerline: true + background: red + foreground: white + - type: python + style: powerline + powerline_symbol: *rtl + invert_powerline: true + background: blue + foreground: black + - type: session + style: powerline + powerline_symbol: *rtl + invert_powerline: true + background: black + foreground: yellow + - type: time + style: diamond + invert_powerline: true + background: white + foreground: black + - type: prompt + alignment: left + newline: true + segments: + - type: status + style: diamond + trailing_diamond: *ltr + background: green + background_templates: + - "{{ if .Error }}red{{ end }}" + foreground: black + foreground_templates: + - "{{ if .Error }}white{{ end }}" + properties: + always_enabled: true diff --git a/dot_config/powershell/profile.ps1 b/dot_config/powershell/profile.ps1 new file mode 100644 index 0000000..8100a78 --- /dev/null +++ b/dot_config/powershell/profile.ps1 @@ -0,0 +1,85 @@ +# PSReadline settings +Set-PSReadlineKeyHandler -Key ctrl+d -Function ViExit +Set-PSReadlineKeyHandler -Key ctrl+a -Function BeginningOfLine +Set-PSReadlineKeyHandler -Key ctrl+e -Function EndOfLine +Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete +Set-PSReadLineKeyHandler -Chord UpArrow -Function HistorySearchBackward +Set-PSReadLineOption -HistorySearchCursorMovesToEnd + +# Prompt setup +Try { + # oh-my-posh prompt + oh-my-posh init pwsh --config "$HOME/.alen.omp.yaml" | Invoke-Expression +} +Catch { + # simple prompt + function prompt { + $lec = $lastExitCode + if (!$(Test-Path variable:lastExitCode) -or ($lec -eq 0)) { + $error = 0 + } else { + $error = 1 + } + Write-Host "" + Write-Host " $(hostname) " -NoNewline -ForegroundColor Black -BackgroundColor Yellow + Write-Host " $(Convert-Path $(Get-Location)) " -NoNewline -ForegroundColor White -BackgroundColor Blue + Write-Host "" -ForegroundColor White -BackgroundColor Black + if ($error) { + Write-Host "❯" -NoNewline -ForegroundColor Red + } else { + Write-Host "❯" -NoNewline -ForegroundColor Green + } + return " " + } +} + +# Auto-env, the lazy way +function Try-AutoVenv { + param ( + [Parameter(Mandatory=$true)] [string]$Path + ) + if (-Not $(Test-Path Env:VIRTUAL_ENV) -And $(Test-Path .\venv\Scripts\Activate.ps1 -PathType Leaf)) { + .\venv\Scripts\Activate.ps1 + } +} + +function Register-AutoVenv { + param() + if (-not (Test-Path function:\global:AutoVenvOrigPrompt)) { + Copy-Item function:\prompt function:\global:AutoVenvOrigPrompt + $global:AutoVenvPromptScriptBlock = { + Try-AutoVenv $pwd + AutoVenvOrigPrompt + } + Set-Content -Path function:\prompt -Value $global:AutoVenvPromptScriptBlock -Force + } +} + +Register-AutoVenv + +# Some aliases +Set-Alias -Name g -Value git +Set-Alias -Name q -Value ipython +Set-Alias -Name which -Value Get-Command + +# Has to run after any prompt mods, so run last +if (Get-Module -ListAvailable -Name ZLocation) { + Import-Module ZLocation + Set-Alias -Name j -Value Invoke-ZLocation +} + +# Colourful ls and l +if (Get-Module -ListAvailable -Name Get-ChildItemColor) { + Import-Module Get-ChildItemColor + Set-Alias l Get-ChildItem -Option AllScope + Set-Alias ls Get-ChildItemColorFormatWide -Option AllScope +} else { + Set-Alias l Get-ChildItem -Option AllScope + Set-Alias ls Get-ChildItem +} + +# TODO: Brew +Try { + $(/opt/homebrew/bin/brew shellenv) | Invoke-Expression +} +Catch {} -- cgit 1.4.1-2-gfad0