mirror of
https://github.com/js0ny/dotfiles.git
synced 2025-12-21 08:43:00 +00:00
chezmoi: powershell
This commit is contained in:
parent
81da252906
commit
298b2290a8
13 changed files with 308 additions and 278 deletions
Binary file not shown.
|
Before Width: | Height: | Size: 1.8 MiB |
|
|
@ -1,41 +1,41 @@
|
|||
# $DOTFILES/tools\powershell\Aliases.ps1
|
||||
# Date: 2024-12-01
|
||||
# Author: js0ny
|
||||
# Aliases for PowerShell
|
||||
|
||||
# Unix Shell Equivalents #
|
||||
Set-Alias "touch" "New-Item"
|
||||
${function:l} = { Get-ChildItem -Force }
|
||||
${function:tree} = { lsd --tree $args }
|
||||
Set-Alias "which" "Get-Command"
|
||||
|
||||
# Editors #
|
||||
Set-Alias "v" "nvim"
|
||||
Set-Alias "c" "code"
|
||||
Get-Command neovide -ErrorAction SilentlyContinue > $null && Set-Alias "gvi" "neovide"
|
||||
|
||||
|
||||
|
||||
# File Creation #
|
||||
function mkcd { param ( [string] $dirname) New-Item -ItemType Directory -Name $dirname && Set-Location $dirname }
|
||||
function tc { param ( [string] $filename) New-Item $filename && code $filename }
|
||||
function tv { param ( [string] $filename) New-Item $filename && nvim $filename }
|
||||
function cdls { param( [string] $dirname) Set-Location $dirname && Get-ChildItem }
|
||||
function zls { param( [string] $dirname) z $dirname && Get-ChildItem }
|
||||
function zl { param( [string] $dirname) z $dirname && lsd }
|
||||
function mt { param( [string] $dirname) New-Item -ItemType File -Name $dirname -Force }
|
||||
|
||||
|
||||
### Dev ###
|
||||
|
||||
# Python & Conda #
|
||||
Set-Alias "py" "python"
|
||||
Set-Alias "ipy" "ipython"
|
||||
|
||||
if ($Env:WEZTERM) {
|
||||
# Environment variable injected by wezterm/wezterm.lua
|
||||
${function:icat} = { wezterm imgcat $args }
|
||||
}
|
||||
elseif ($Env:KITTY) {
|
||||
${function:icat} = { kitty +kitten icat $args }
|
||||
}
|
||||
# $DOTFILES/tools\powershell\Aliases.ps1
|
||||
# Date: 2024-12-01
|
||||
# Author: js0ny
|
||||
# Aliases for PowerShell
|
||||
|
||||
# Unix Shell Equivalents #
|
||||
Set-Alias "touch" "New-Item"
|
||||
${function:l} = { Get-ChildItem -Force }
|
||||
${function:tree} = { lsd --tree $args }
|
||||
Set-Alias "which" "Get-Command"
|
||||
|
||||
# Editors #
|
||||
Set-Alias "v" "nvim"
|
||||
Set-Alias "c" "code"
|
||||
Get-Command neovide -ErrorAction SilentlyContinue > $null && Set-Alias "gvi" "neovide"
|
||||
|
||||
|
||||
|
||||
# File Creation #
|
||||
function mkcd { param ( [string] $dirname) New-Item -ItemType Directory -Name $dirname && Set-Location $dirname }
|
||||
function tc { param ( [string] $filename) New-Item $filename && code $filename }
|
||||
function tv { param ( [string] $filename) New-Item $filename && nvim $filename }
|
||||
function cdls { param( [string] $dirname) Set-Location $dirname && Get-ChildItem }
|
||||
function zls { param( [string] $dirname) z $dirname && Get-ChildItem }
|
||||
function zl { param( [string] $dirname) z $dirname && lsd }
|
||||
function mt { param( [string] $dirname) New-Item -ItemType File -Name $dirname -Force }
|
||||
|
||||
|
||||
### Dev ###
|
||||
|
||||
# Python & Conda #
|
||||
Set-Alias "py" "python"
|
||||
Set-Alias "ipy" "ipython"
|
||||
|
||||
if ($Env:WEZTERM) {
|
||||
# Environment variable injected by wezterm/wezterm.lua
|
||||
${function:icat} = { wezterm imgcat $args }
|
||||
}
|
||||
elseif ($Env:KITTY) {
|
||||
${function:icat} = { kitty +kitten icat $args }
|
||||
}
|
||||
|
|
@ -1,31 +1,31 @@
|
|||
# aka PSReadLine
|
||||
|
||||
# read key: [System.Console]::ReadKey()
|
||||
# get current bindings: Get-PSReadLineKeyHandler
|
||||
|
||||
# PSReadLineOptions
|
||||
Set-PSReadLineOption -EditMode Vi # Vi Keybindings
|
||||
Set-PSReadLineOption -PredictionViewStyle InlineView
|
||||
Set-PSReadLineOption -PredictionSource HistoryAndPlugin
|
||||
# Set-PSReadLineOption -ContinuationPrompt "`e[36m CR > " # Use Starship instead
|
||||
# PSReadLineKeyHandlers
|
||||
Set-PSReadLineKeyHandler -Chord "Control+Oem4" -Function ViCommandMode -ViMode Insert # ^[ to Escape
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+a" -Function BeginningOfLine
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+e" -Function EndOfLine
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+p" -Function PreviousHistory
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+f" -Function AcceptNextSuggestionWord
|
||||
Set-PSReadLineKeyHandler -Chord "Alt+f" -Function AcceptSuggestion
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+n" -Function NextHistory
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+w" -Function BackwardKillWord
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+Backspace" -Function BackwardKillWord
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+Shift+Backspace" -Function BackwardKillLine
|
||||
Set-PSReadLineKeyHandler -Chord "Alt+Backspace" -Function BackwardKillLine
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+Delete" -Function KillWord
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+Shift+Delete" -Function KillLine
|
||||
Set-PSReadLineKeyHandler -Chord "Alt+Delete" -Function KillLine
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+c" -Function CopyOrCancelLine -ViMode Insert
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+c" -Function CopyOrCancelLine -ViMode Command
|
||||
## Use <Tab> to Invoke MenuComplete
|
||||
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
|
||||
|
||||
# aka PSReadLine
|
||||
|
||||
# read key: [System.Console]::ReadKey()
|
||||
# get current bindings: Get-PSReadLineKeyHandler
|
||||
|
||||
# PSReadLineOptions
|
||||
Set-PSReadLineOption -EditMode Vi # Vi Keybindings
|
||||
Set-PSReadLineOption -PredictionViewStyle InlineView
|
||||
Set-PSReadLineOption -PredictionSource HistoryAndPlugin
|
||||
# Set-PSReadLineOption -ContinuationPrompt "`e[36m CR > " # Use Starship instead
|
||||
# PSReadLineKeyHandlers
|
||||
Set-PSReadLineKeyHandler -Chord "Control+Oem4" -Function ViCommandMode -ViMode Insert # ^[ to Escape
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+a" -Function BeginningOfLine
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+e" -Function EndOfLine
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+p" -Function PreviousHistory
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+f" -Function AcceptNextSuggestionWord
|
||||
Set-PSReadLineKeyHandler -Chord "Alt+f" -Function AcceptSuggestion
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+n" -Function NextHistory
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+w" -Function BackwardKillWord
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+Backspace" -Function BackwardKillWord
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+Shift+Backspace" -Function BackwardKillLine
|
||||
Set-PSReadLineKeyHandler -Chord "Alt+Backspace" -Function BackwardKillLine
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+Delete" -Function KillWord
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+Shift+Delete" -Function KillLine
|
||||
Set-PSReadLineKeyHandler -Chord "Alt+Delete" -Function KillLine
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+c" -Function CopyOrCancelLine -ViMode Insert
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+c" -Function CopyOrCancelLine -ViMode Command
|
||||
## Use <Tab> to Invoke MenuComplete
|
||||
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
|
||||
|
||||
. $(Join-Path $DOTFILES "tools" "powershell" "Keymap" "Colemak.ps1")
|
||||
23
dot_config/powershell/Microsoft.PowerShell_profile.ps1
Normal file
23
dot_config/powershell/Microsoft.PowerShell_profile.ps1
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# $XDG_CONFIG_HOME/powershell/Microsoft.PowerShell_profile.ps1
|
||||
# ln -sf $DOTFILES/mac/Microsoft.PowerShell_profile.ps1 $XDG_CONFIG_HOME/powershell/Microsoft.PowerShell_profile.ps1
|
||||
### Variables ###
|
||||
|
||||
$DOTFILES = "$HOME/.dotfiles"
|
||||
|
||||
### Load Configs ###
|
||||
|
||||
Get-ChildItem -Path $(Join-Path $DOTFILES "tools" "powershell") -Filter *.ps1 | ForEach-Object {. $_}
|
||||
|
||||
## Aliases ###
|
||||
|
||||
# PowerShell Equivalents #
|
||||
|
||||
# Set-Alias "curl" "Invoke-WebRequest"
|
||||
# Set-Alias "man" "Get-Help"
|
||||
Set-Alias "kill" "Stop-Process"
|
||||
Set-Alias "open" "Invoke-Item" # Use ii instead of open
|
||||
|
||||
# Dev #
|
||||
|
||||
${function:zshcfg} = { nvim ~/.zshrc }
|
||||
${function:bashcfg} = { nvim ~/.bashrc }
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
# Import-Module -Name Terminal-Icons
|
||||
Import-Module -Name CompletionPredictor
|
||||
if ($IsWindows) {
|
||||
# Chocolatey
|
||||
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
|
||||
if (Test-Path($ChocolateyProfile)) { Import-Module "$ChocolateyProfile" }
|
||||
# WinGet
|
||||
Import-Module -Name Microsoft.WinGet.CommandNotFound #f45873b3-b655-43a6-b217-97c00aa0db58
|
||||
}
|
||||
|
||||
Import-Module -Name PSFzf
|
||||
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl-r" -ScriptBlock { Invoke-FuzzyHistory }
|
||||
# Import-Module -Name Terminal-Icons
|
||||
Import-Module -Name CompletionPredictor
|
||||
if ($IsWindows) {
|
||||
# Chocolatey
|
||||
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
|
||||
if (Test-Path($ChocolateyProfile)) { Import-Module "$ChocolateyProfile" }
|
||||
# WinGet
|
||||
Import-Module -Name Microsoft.WinGet.CommandNotFound #f45873b3-b655-43a6-b217-97c00aa0db58
|
||||
}
|
||||
|
||||
Import-Module -Name PSFzf
|
||||
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl-r" -ScriptBlock { Invoke-FuzzyHistory }
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
# ${function:~} = { Set-Location -Path ~ } cd is better
|
||||
${function:...} = { Set-Location -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) }
|
||||
${function:....} = { Set-Location -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) -ChildPath ..) }
|
||||
${function:.....} = { Set-Location -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) -ChildPath ..) -ChildPath ..) }
|
||||
${function:......} = { Set-Location -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) -ChildPath ..) -ChildPath ..) -ChildPath ..) }
|
||||
|
||||
# Absolute navigation
|
||||
${function:docs} = { Set-Location -Path (Join-Path -Path $HOME -ChildPath "Documents") }
|
||||
${function:down} = { Set-Location -Path (Join-Path -Path $HOME -ChildPath "Downloads") }
|
||||
${function:dt} = { Set-Location -Path (Join-Path -Path $HOME -ChildPath "Desktop") }
|
||||
${function:one} = { Set-Location -Path (Join-Path -Path $HOME -ChildPath "OneDrive") }
|
||||
# ${function:~} = { Set-Location -Path ~ } cd is better
|
||||
${function:...} = { Set-Location -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) }
|
||||
${function:....} = { Set-Location -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) -ChildPath ..) }
|
||||
${function:.....} = { Set-Location -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) -ChildPath ..) -ChildPath ..) }
|
||||
${function:......} = { Set-Location -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) -ChildPath ..) -ChildPath ..) -ChildPath ..) }
|
||||
|
||||
# Absolute navigation
|
||||
${function:docs} = { Set-Location -Path (Join-Path -Path $HOME -ChildPath "Documents") }
|
||||
${function:down} = { Set-Location -Path (Join-Path -Path $HOME -ChildPath "Downloads") }
|
||||
${function:dt} = { Set-Location -Path (Join-Path -Path $HOME -ChildPath "Desktop") }
|
||||
${function:one} = { Set-Location -Path (Join-Path -Path $HOME -ChildPath "OneDrive") }
|
||||
|
|
@ -1,144 +1,144 @@
|
|||
# $DOTFILES/tools\powershell\Prompt.ps1
|
||||
# Date: 2024-12-01
|
||||
# Author: js0ny
|
||||
# Use starship to set prompt
|
||||
|
||||
# Invoke-Expression (&starship init powershell)
|
||||
|
||||
|
||||
function formatFG {
|
||||
param(
|
||||
[string]$RGB
|
||||
)
|
||||
if ($RGB -eq "-1") {
|
||||
return "`e[39m"
|
||||
}
|
||||
$R = $RGB.Substring(0, 2)
|
||||
$G = $RGB.Substring(2, 2)
|
||||
$B = $RGB.Substring(4, 2)
|
||||
# Convert hex to RGB
|
||||
$R = [int]::Parse($R, [System.Globalization.NumberStyles]::HexNumber)
|
||||
$G = [int]::Parse($G, [System.Globalization.NumberStyles]::HexNumber)
|
||||
$B = [int]::Parse($B, [System.Globalization.NumberStyles]::HexNumber)
|
||||
return "`e[38;2;$R;$G;${B}m"
|
||||
}
|
||||
|
||||
function formatBG {
|
||||
param(
|
||||
[string]$RGB
|
||||
)
|
||||
if ($RGB -eq "-1") {
|
||||
return "`e[49m"
|
||||
}
|
||||
$R = $RGB.Substring(0, 2)
|
||||
$G = $RGB.Substring(2, 2)
|
||||
$B = $RGB.Substring(4, 2)
|
||||
# Convert hex to RGB
|
||||
$R = [int]::Parse($R, [System.Globalization.NumberStyles]::HexNumber)
|
||||
$G = [int]::Parse($G, [System.Globalization.NumberStyles]::HexNumber)
|
||||
$B = [int]::Parse($B, [System.Globalization.NumberStyles]::HexNumber)
|
||||
return "`e[48;2;$R;$G;${B}m"
|
||||
}
|
||||
function formatPowerlineText {
|
||||
param(
|
||||
[string]$FG,
|
||||
[string]$BG,
|
||||
[string]$PLBG,
|
||||
[string]$Text
|
||||
)
|
||||
$ResumeSequece = "`e[0m"
|
||||
$TextFG = formatFG -RGB $FG
|
||||
$TextBG = formatBG -RGB $BG
|
||||
$PLFG = formatFG -RGB $BG
|
||||
$PLBG = formatBG -RGB $PLBG
|
||||
return "$TextFG$TextBG $Text $PLFG$PLBG$ResumeSequece"
|
||||
}
|
||||
|
||||
function prompt {
|
||||
if ($pwd.Path -eq $HOME) {
|
||||
$cwd = "~"
|
||||
} else {
|
||||
$cwd = $pwd.ProviderPath
|
||||
}
|
||||
$time = Get-Date -Format "HH:mm"
|
||||
$ResumeSequece = "`e[0m"
|
||||
$FG0 = "FFFFFF"
|
||||
$BG0 = "9A348E"
|
||||
$BG1 = "DA627D"
|
||||
$BG2 = "FCA17D"
|
||||
$FG1 = "035E82"
|
||||
$time = formatPowerlineText $FG0 $BG0 $BG1 $time
|
||||
$cwd = formatPowerlineText $FG0 $BG1 $BG2 $cwd
|
||||
$ps = formatPowerlineText $FG1 $BG2 "-1" "PS"
|
||||
|
||||
"$time$cwd$ps$ResumeSequece "
|
||||
|
||||
}
|
||||
|
||||
function Invoke-Starship {
|
||||
Invoke-Expression (&starship init powershell)
|
||||
}
|
||||
|
||||
Import-Module Catppuccin
|
||||
|
||||
$Flavor = $Catppuccin['Mocha']
|
||||
|
||||
# The following colors are used by PowerShell's formatting
|
||||
# Again PS 7.2+ only
|
||||
$PSStyle.Formatting.Debug = $Flavor.Sky.Foreground()
|
||||
$PSStyle.Formatting.Error = $Flavor.Red.Foreground()
|
||||
$PSStyle.Formatting.ErrorAccent = $Flavor.Blue.Foreground()
|
||||
$PSStyle.Formatting.FormatAccent = $Flavor.Teal.Foreground()
|
||||
$PSStyle.Formatting.TableHeader = $Flavor.Rosewater.Foreground()
|
||||
$PSStyle.Formatting.Verbose = $Flavor.Yellow.Foreground()
|
||||
$PSStyle.Formatting.Warning = $Flavor.Peach.Foreground()
|
||||
|
||||
$Colors = @{
|
||||
# Largely based on the Code Editor style guide
|
||||
# Emphasis, ListPrediction and ListPredictionSelected are inspired by the Catppuccin fzf theme
|
||||
|
||||
# Powershell colours
|
||||
Emphasis = $Flavor.Red.Foreground()
|
||||
Selection = $Flavor.Surface0.Background()
|
||||
|
||||
# PSReadLine prediction colours
|
||||
InlinePrediction = $Flavor.Overlay0.Foreground()
|
||||
ListPrediction = $Flavor.Mauve.Foreground()
|
||||
ListPredictionSelected = $Flavor.Surface0.Background()
|
||||
|
||||
# Syntax highlighting
|
||||
Command = $Flavor.Blue.Foreground()
|
||||
Comment = $Flavor.Overlay0.Foreground()
|
||||
Default = $Flavor.Text.Foreground()
|
||||
Error = $Flavor.Red.Foreground()
|
||||
Keyword = $Flavor.Mauve.Foreground()
|
||||
Member = $Flavor.Rosewater.Foreground()
|
||||
Number = $Flavor.Peach.Foreground()
|
||||
Operator = $Flavor.Sky.Foreground()
|
||||
Parameter = $Flavor.Pink.Foreground()
|
||||
String = $Flavor.Green.Foreground()
|
||||
Type = $Flavor.Yellow.Foreground()
|
||||
Variable = $Flavor.Lavender.Foreground()
|
||||
}
|
||||
|
||||
# Set the colours
|
||||
Set-PSReadLineOption -Colors $Colors
|
||||
|
||||
# Smarter cd
|
||||
# Init zoxide apter starship to avoid conflicts
|
||||
# https://github.com/ajeetdsouza/zoxide/issues/723
|
||||
if (Get-Command zoxide -ErrorAction SilentlyContinue) {
|
||||
Invoke-Expression (& { (zoxide init powershell | Out-String) })
|
||||
${function:...} = { z -Path (Join-Path -Path .. -ChildPath ..) }
|
||||
${function:....} = { z -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) }
|
||||
${function:.....} = { z -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) -ChildPath ..) }
|
||||
${function:......} = { z -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) -ChildPath ..) -ChildPath ..) }
|
||||
${function:z-} = { z - }
|
||||
}
|
||||
else {
|
||||
${function:...} = { Set-Location -Path (Join-Path -Path .. -ChildPath ..) }
|
||||
${function:....} = { Set-Location -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) }
|
||||
${function:.....} = { Set-Location -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) -ChildPath ..) }
|
||||
${function:......} = { Set-Location -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) -ChildPath ..) -ChildPath ..) }
|
||||
${function:z-} = { Set-Location - }
|
||||
}
|
||||
# $DOTFILES/tools\powershell\Prompt.ps1
|
||||
# Date: 2024-12-01
|
||||
# Author: js0ny
|
||||
# Use starship to set prompt
|
||||
|
||||
# Invoke-Expression (&starship init powershell)
|
||||
|
||||
|
||||
function formatFG {
|
||||
param(
|
||||
[string]$RGB
|
||||
)
|
||||
if ($RGB -eq "-1") {
|
||||
return "`e[39m"
|
||||
}
|
||||
$R = $RGB.Substring(0, 2)
|
||||
$G = $RGB.Substring(2, 2)
|
||||
$B = $RGB.Substring(4, 2)
|
||||
# Convert hex to RGB
|
||||
$R = [int]::Parse($R, [System.Globalization.NumberStyles]::HexNumber)
|
||||
$G = [int]::Parse($G, [System.Globalization.NumberStyles]::HexNumber)
|
||||
$B = [int]::Parse($B, [System.Globalization.NumberStyles]::HexNumber)
|
||||
return "`e[38;2;$R;$G;${B}m"
|
||||
}
|
||||
|
||||
function formatBG {
|
||||
param(
|
||||
[string]$RGB
|
||||
)
|
||||
if ($RGB -eq "-1") {
|
||||
return "`e[49m"
|
||||
}
|
||||
$R = $RGB.Substring(0, 2)
|
||||
$G = $RGB.Substring(2, 2)
|
||||
$B = $RGB.Substring(4, 2)
|
||||
# Convert hex to RGB
|
||||
$R = [int]::Parse($R, [System.Globalization.NumberStyles]::HexNumber)
|
||||
$G = [int]::Parse($G, [System.Globalization.NumberStyles]::HexNumber)
|
||||
$B = [int]::Parse($B, [System.Globalization.NumberStyles]::HexNumber)
|
||||
return "`e[48;2;$R;$G;${B}m"
|
||||
}
|
||||
function formatPowerlineText {
|
||||
param(
|
||||
[string]$FG,
|
||||
[string]$BG,
|
||||
[string]$PLBG,
|
||||
[string]$Text
|
||||
)
|
||||
$ResumeSequece = "`e[0m"
|
||||
$TextFG = formatFG -RGB $FG
|
||||
$TextBG = formatBG -RGB $BG
|
||||
$PLFG = formatFG -RGB $BG
|
||||
$PLBG = formatBG -RGB $PLBG
|
||||
return "$TextFG$TextBG $Text $PLFG$PLBG$ResumeSequece"
|
||||
}
|
||||
|
||||
function prompt {
|
||||
if ($pwd.Path -eq $HOME) {
|
||||
$cwd = "~"
|
||||
} else {
|
||||
$cwd = $pwd.ProviderPath
|
||||
}
|
||||
$time = Get-Date -Format "HH:mm"
|
||||
$ResumeSequece = "`e[0m"
|
||||
$FG0 = "FFFFFF"
|
||||
$BG0 = "9A348E"
|
||||
$BG1 = "DA627D"
|
||||
$BG2 = "FCA17D"
|
||||
$FG1 = "035E82"
|
||||
$time = formatPowerlineText $FG0 $BG0 $BG1 $time
|
||||
$cwd = formatPowerlineText $FG0 $BG1 $BG2 $cwd
|
||||
$ps = formatPowerlineText $FG1 $BG2 "-1" "PS"
|
||||
|
||||
"$time$cwd$ps$ResumeSequece "
|
||||
|
||||
}
|
||||
|
||||
function Invoke-Starship {
|
||||
Invoke-Expression (&starship init powershell)
|
||||
}
|
||||
|
||||
Import-Module Catppuccin
|
||||
|
||||
$Flavor = $Catppuccin['Mocha']
|
||||
|
||||
# The following colors are used by PowerShell's formatting
|
||||
# Again PS 7.2+ only
|
||||
$PSStyle.Formatting.Debug = $Flavor.Sky.Foreground()
|
||||
$PSStyle.Formatting.Error = $Flavor.Red.Foreground()
|
||||
$PSStyle.Formatting.ErrorAccent = $Flavor.Blue.Foreground()
|
||||
$PSStyle.Formatting.FormatAccent = $Flavor.Teal.Foreground()
|
||||
$PSStyle.Formatting.TableHeader = $Flavor.Rosewater.Foreground()
|
||||
$PSStyle.Formatting.Verbose = $Flavor.Yellow.Foreground()
|
||||
$PSStyle.Formatting.Warning = $Flavor.Peach.Foreground()
|
||||
|
||||
$Colors = @{
|
||||
# Largely based on the Code Editor style guide
|
||||
# Emphasis, ListPrediction and ListPredictionSelected are inspired by the Catppuccin fzf theme
|
||||
|
||||
# Powershell colours
|
||||
Emphasis = $Flavor.Red.Foreground()
|
||||
Selection = $Flavor.Surface0.Background()
|
||||
|
||||
# PSReadLine prediction colours
|
||||
InlinePrediction = $Flavor.Overlay0.Foreground()
|
||||
ListPrediction = $Flavor.Mauve.Foreground()
|
||||
ListPredictionSelected = $Flavor.Surface0.Background()
|
||||
|
||||
# Syntax highlighting
|
||||
Command = $Flavor.Blue.Foreground()
|
||||
Comment = $Flavor.Overlay0.Foreground()
|
||||
Default = $Flavor.Text.Foreground()
|
||||
Error = $Flavor.Red.Foreground()
|
||||
Keyword = $Flavor.Mauve.Foreground()
|
||||
Member = $Flavor.Rosewater.Foreground()
|
||||
Number = $Flavor.Peach.Foreground()
|
||||
Operator = $Flavor.Sky.Foreground()
|
||||
Parameter = $Flavor.Pink.Foreground()
|
||||
String = $Flavor.Green.Foreground()
|
||||
Type = $Flavor.Yellow.Foreground()
|
||||
Variable = $Flavor.Lavender.Foreground()
|
||||
}
|
||||
|
||||
# Set the colours
|
||||
Set-PSReadLineOption -Colors $Colors
|
||||
|
||||
# Smarter cd
|
||||
# Init zoxide apter starship to avoid conflicts
|
||||
# https://github.com/ajeetdsouza/zoxide/issues/723
|
||||
if (Get-Command zoxide -ErrorAction SilentlyContinue) {
|
||||
Invoke-Expression (& { (zoxide init powershell | Out-String) })
|
||||
${function:...} = { z -Path (Join-Path -Path .. -ChildPath ..) }
|
||||
${function:....} = { z -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) }
|
||||
${function:.....} = { z -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) -ChildPath ..) }
|
||||
${function:......} = { z -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) -ChildPath ..) -ChildPath ..) }
|
||||
${function:z-} = { z - }
|
||||
}
|
||||
else {
|
||||
${function:...} = { Set-Location -Path (Join-Path -Path .. -ChildPath ..) }
|
||||
${function:....} = { Set-Location -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) }
|
||||
${function:.....} = { Set-Location -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) -ChildPath ..) }
|
||||
${function:......} = { Set-Location -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) -ChildPath ..) -ChildPath ..) }
|
||||
${function:z-} = { Set-Location - }
|
||||
}
|
||||
|
|
@ -1,39 +1,39 @@
|
|||
# PowerShell Profile
|
||||
|
||||
This is the cross-platform PowerShell profile for PowerShell Core
|
||||
|
||||
```text
|
||||
.
|
||||
├── Aliases.ps1
|
||||
├── Keymap.ps1 # keymaps, optimize for Vi-Mode and Colemak
|
||||
├── Modules.ps1
|
||||
├── Navigation.ps1
|
||||
├── Prompt.ps1
|
||||
├── readme.md
|
||||
└── Scripts.ps1
|
||||
|
||||
1 directory, 7 files
|
||||
```
|
||||
|
||||
| Keymap | Action | Mode |
|
||||
| ------ | -------------------- | ------ |
|
||||
| `^a` | To Beginning of Line | All |
|
||||
| `^e` | To End of Line | All |
|
||||
| `^[` | To Normal Mode | Insert |
|
||||
|
||||
## `Get-Command` vs `which.exe` under Windows
|
||||
|
||||
```powershell
|
||||
PS > hyperfine "pwsh.exe -NoProfile -Command 'Get-Command which'" "pwsh.exe -NoProfile -Command 'which which'" --warmup 10
|
||||
Benchmark 1: pwsh.exe -NoProfile -Command 'Get-Command which'
|
||||
Time (mean ± σ): 152.1 ms ± 1.3 ms [User: 112.2 ms, System: 89.3 ms]
|
||||
Range (min … max): 150.0 ms … 155.3 ms 18 runs
|
||||
|
||||
Benchmark 2: pwsh.exe -NoProfile -Command 'which which'
|
||||
Time (mean ± σ): 153.7 ms ± 6.4 ms [User: 126.7 ms, System: 101.9 ms]
|
||||
Range (min … max): 147.8 ms … 169.5 ms 19 runs
|
||||
|
||||
Summary
|
||||
pwsh.exe -NoProfile -Command 'Get-Command which' ran
|
||||
1.01 ± 0.04 times faster than pwsh.exe -NoProfile -Command 'which which'
|
||||
```
|
||||
# PowerShell Profile
|
||||
|
||||
This is the cross-platform PowerShell profile for PowerShell Core
|
||||
|
||||
```text
|
||||
.
|
||||
├── Aliases.ps1
|
||||
├── Keymap.ps1 # keymaps, optimize for Vi-Mode and Colemak
|
||||
├── Modules.ps1
|
||||
├── Navigation.ps1
|
||||
├── Prompt.ps1
|
||||
├── readme.md
|
||||
└── Scripts.ps1
|
||||
|
||||
1 directory, 7 files
|
||||
```
|
||||
|
||||
| Keymap | Action | Mode |
|
||||
| ------ | -------------------- | ------ |
|
||||
| `^a` | To Beginning of Line | All |
|
||||
| `^e` | To End of Line | All |
|
||||
| `^[` | To Normal Mode | Insert |
|
||||
|
||||
## `Get-Command` vs `which.exe` under Windows
|
||||
|
||||
```powershell
|
||||
PS > hyperfine "pwsh.exe -NoProfile -Command 'Get-Command which'" "pwsh.exe -NoProfile -Command 'which which'" --warmup 10
|
||||
Benchmark 1: pwsh.exe -NoProfile -Command 'Get-Command which'
|
||||
Time (mean ± σ): 152.1 ms ± 1.3 ms [User: 112.2 ms, System: 89.3 ms]
|
||||
Range (min … max): 150.0 ms … 155.3 ms 18 runs
|
||||
|
||||
Benchmark 2: pwsh.exe -NoProfile -Command 'which which'
|
||||
Time (mean ± σ): 153.7 ms ± 6.4 ms [User: 126.7 ms, System: 101.9 ms]
|
||||
Range (min … max): 147.8 ms … 169.5 ms 19 runs
|
||||
|
||||
Summary
|
||||
pwsh.exe -NoProfile -Command 'Get-Command which' ran
|
||||
1.01 ± 0.04 times faster than pwsh.exe -NoProfile -Command 'which which'
|
||||
```
|
||||
1
dot_config/powershell/xaa
Normal file
1
dot_config/powershell/xaa
Normal file
|
|
@ -0,0 +1 @@
|
|||
/home/js0ny/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/opt/microsoft/powershell/7/Modules
|
||||
6
scripts/run_once_powershell.ps1
Normal file
6
scripts/run_once_powershell.ps1
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env pwsh
|
||||
|
||||
Install-Package PSFzf -Force
|
||||
Install-Package CompletionPredictor -Force
|
||||
|
||||
git clone --depth 1 https://github.com/catppuccin/powershell.git (Join-Path $Env:PSModulePath.Split(':')[0] Catppuccin)
|
||||
Loading…
Add table
Add a link
Reference in a new issue