summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlen <alen@dotfiles.xyz>2023-09-13 00:28:43 +0400
committerAlen <alen@dotfiles.xyz>2023-09-14 01:36:41 +0400
commit73ccf329640316f26305e6b0c8dc75956b370237 (patch)
tree10c2717e4b299b78118416dea93f54d9ccd3d8a5
parent96326bbd44e47f2485cb378401e7a198ec3092a4 (diff)
Add basic PowerShell profile
-rw-r--r--.chezmoiignore6
-rw-r--r--Documents/PowerShell/profile.ps1.tmpl1
-rw-r--r--OneDrive/Documents/PowerShell/profile.ps1.tmpl1
-rw-r--r--dot_alen.omp.yaml75
-rw-r--r--dot_config/powershell/profile.ps185
5 files changed, 168 insertions, 0 deletions
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:
+  - &ltr 
+  - &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 {}