diff --git a/_assets/windows-1.png b/_assets/windows-1.png deleted file mode 100644 index 313ae1c..0000000 Binary files a/_assets/windows-1.png and /dev/null differ diff --git a/tools/powershell/Aliases.ps1 b/dot_config/powershell/Aliases.ps1 similarity index 96% rename from tools/powershell/Aliases.ps1 rename to dot_config/powershell/Aliases.ps1 index 45948f7..440782f 100644 --- a/tools/powershell/Aliases.ps1 +++ b/dot_config/powershell/Aliases.ps1 @@ -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 } +} diff --git a/tools/powershell/Completions.ps1 b/dot_config/powershell/Completions.ps1 similarity index 100% rename from tools/powershell/Completions.ps1 rename to dot_config/powershell/Completions.ps1 diff --git a/tools/powershell/Environment.ps1 b/dot_config/powershell/Environment.ps1 similarity index 100% rename from tools/powershell/Environment.ps1 rename to dot_config/powershell/Environment.ps1 diff --git a/tools/powershell/Keymap.ps1 b/dot_config/powershell/Keymap.ps1 similarity index 98% rename from tools/powershell/Keymap.ps1 rename to dot_config/powershell/Keymap.ps1 index 5e67b1f..184bd44 100644 --- a/tools/powershell/Keymap.ps1 +++ b/dot_config/powershell/Keymap.ps1 @@ -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 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 to Invoke MenuComplete +Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete + . $(Join-Path $DOTFILES "tools" "powershell" "Keymap" "Colemak.ps1") \ No newline at end of file diff --git a/tools/powershell/Keymap/Colemak.ps1 b/dot_config/powershell/Keymap/Colemak.ps1 similarity index 100% rename from tools/powershell/Keymap/Colemak.ps1 rename to dot_config/powershell/Keymap/Colemak.ps1 diff --git a/dot_config/powershell/Microsoft.PowerShell_profile.ps1 b/dot_config/powershell/Microsoft.PowerShell_profile.ps1 new file mode 100644 index 0000000..ac0ce0d --- /dev/null +++ b/dot_config/powershell/Microsoft.PowerShell_profile.ps1 @@ -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 } diff --git a/tools/powershell/Modules.ps1 b/dot_config/powershell/Modules.ps1 similarity index 97% rename from tools/powershell/Modules.ps1 rename to dot_config/powershell/Modules.ps1 index cdc48e8..34440e4 100644 --- a/tools/powershell/Modules.ps1 +++ b/dot_config/powershell/Modules.ps1 @@ -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 } diff --git a/tools/powershell/Navigation.ps1 b/dot_config/powershell/Navigation.ps1 similarity index 98% rename from tools/powershell/Navigation.ps1 rename to dot_config/powershell/Navigation.ps1 index 99a55ac..ece1c11 100644 --- a/tools/powershell/Navigation.ps1 +++ b/dot_config/powershell/Navigation.ps1 @@ -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") } diff --git a/tools/powershell/Prompt.ps1 b/dot_config/powershell/Prompt.ps1 similarity index 97% rename from tools/powershell/Prompt.ps1 rename to dot_config/powershell/Prompt.ps1 index 1ae9545..5257100 100644 --- a/tools/powershell/Prompt.ps1 +++ b/dot_config/powershell/Prompt.ps1 @@ -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 - } +} diff --git a/tools/powershell/readme.md b/dot_config/powershell/readme.md similarity index 97% rename from tools/powershell/readme.md rename to dot_config/powershell/readme.md index db44094..6d7b1f2 100644 --- a/tools/powershell/readme.md +++ b/dot_config/powershell/readme.md @@ -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' +``` diff --git a/dot_config/powershell/xaa b/dot_config/powershell/xaa new file mode 100644 index 0000000..67fbfd1 --- /dev/null +++ b/dot_config/powershell/xaa @@ -0,0 +1 @@ +/home/js0ny/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/opt/microsoft/powershell/7/Modules diff --git a/scripts/run_once_powershell.ps1 b/scripts/run_once_powershell.ps1 new file mode 100644 index 0000000..acb711d --- /dev/null +++ b/scripts/run_once_powershell.ps1 @@ -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)