feat(shell): Use one keymaps for shell

This commit is contained in:
js0ny 2025-01-28 14:26:25 +00:00
parent 68ff1bb357
commit 2346c13564
19 changed files with 530 additions and 265 deletions

View file

@ -2,27 +2,28 @@
# Date: 2024-12-01
# Author: js0ny
# Aliases for PowerShell
### VARIABLES ###
$EDITOR = "code"
# Shell Equivalents #
# Unix Shell Equivalents #
Set-Alias "touch" "New-Item"
${function:l} = { Get-ChildItem -Force }
${function:tree} = { lsd.exe --tree $args }
${function:tree} = { lsd --tree $args }
Set-Alias "which" "Get-Command"
# Shell Configurations #
${function:pulldots} = { Set-Location -Path $DOTFILES && git pull }
# Editors #
Set-Alias "v" "nvim"
Set-Alias "c" "code"
Set-Alias "gvi" "neovide"
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 }
### Dev ###
@ -30,7 +31,10 @@ function cdls { param( [string] $dirname) Set-Location $dirname && Get-ChildItem
Set-Alias "py" "python"
Set-Alias "ipy" "ipython"
if ($isWindows) {
# Debugging
# function kex { wsl -d kali-linux kex --sl -s }
if ($Env:WEZTERM) {
# Environment variable injected by wezterm/wezterm.lua
${function:icat} = { wezterm imgcat $args }
}
elseif ($Env:KITTY) {
${function:icat} = { kitty +kitten icat $args }
}

View file

@ -1,8 +0,0 @@
if ($Env:WEZTERM) {
# Environment variable injected by wezterm/wezterm.lua
${function:icat} = { wezterm imgcat $args }
}
elseif ($Env:KITTY) {
${function:icat} = { kitty +kitten icat $args }
}

View file

@ -8,3 +8,6 @@
# interactive session.
$env:IPYTHONDIR = "$env:AppData\ipython"
$env:EDITOR = "code --wait"
$env:VISUAL = "code --wait"
$env:PAGER = "less"

View file

@ -1,7 +1,11 @@
# aka PSReadLine
# read key: [System.Console]::ReadKey()
# get current bindings: Get-PSReadLineKeyHandler
# PSReadLineOptions
Set-PSReadLineOption -EditMode Vi # Vi Keybindings
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -PredictionViewStyle InlineView
Set-PSReadLineOption -PredictionSource HistoryAndPlugin
# Set-PSReadLineOption -ContinuationPrompt "`e[36m CR > " # Use Starship instead
# PSReadLineKeyHandlers
@ -24,7 +28,15 @@ Set-PSReadLineKeyHandler -Chord "Control+Oem4" -Function ViCommandMode -ViMode I
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+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
## Use <Tab> to Invoke MenuComplete
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete

View file

@ -1,14 +1,28 @@
# ${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 ..) }
${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: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") }
Invoke-Expression (& { (zoxide init powershell | Out-String) })
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 - }
}

View file

@ -20,31 +20,31 @@ $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()
# Largely based on the Code Editor style guide
# Emphasis, ListPrediction and ListPredictionSelected are inspired by the Catppuccin fzf theme
# 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()
# 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