Windows and powershell stuff

This commit is contained in:
elkowar 2025-01-04 20:40:51 +01:00
parent afe1aa4e5e
commit 7ec7f524f3
No known key found for this signature in database
3 changed files with 26 additions and 85 deletions

View file

@ -1,79 +0,0 @@
# todo I looked again and you could use the [System.Drawing.Color] type to parse and store your colors
# [drawing.color]("#ffffff")
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_ansi_terminals?view=powershell-7.2
if ($host.Name -eq "ConsoleHost")
{
Import-Module PSReadline
Set-PSReadLineKeyHandler -Chord Control+Delete -Function BackwardKillWord
Set-PSReadLineKeyHandler -Chord Control+Backspace -Function BackwardKillWord
Set-PSReadLineKeyHandler -Chord Control+RightArrow -Function NextWord
Set-PSReadLineKeyHandler -Chord Control+LeftArrow -Function BackwardWord
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler Key DownArrow -Function HistorySearchForward
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
Set-PSReadLineKeyHandler -Chord Control+c -Function RevertLine
#Set-PSReadlineKeyHandler -Chord Control+C -Function CancelLine
}
function Convert-HexToAnsiiEscape
{
param ([Parameter(Mandatory)] [string]$hex)
$nohash = $hex.substring(1)
$rgb = $nohash -split '(..)' -ne '' | ForEach-Object { [Convert]::ToInt64($_, 16) }
[char]27 + "$ansi_escape[38;2;{0};{1};{2}m" -f $rgb[0], $rgb[1],$rgb[2]
}
$Colors = @{
cyan = Convert-HexToAnsiiEscape("#8ec07c")
white = Convert-HexToAnsiiEscape("#ebdbb2")
green = Convert-HexToAnsiiEscape("#b8bb26")
}
function prompt_git_status
{
try
{
$branch = (git branch | Select-String -Pattern "\* ") -Replace "\* ",""
$change_indicator = (git status --short) ? "*" : ""
$branch ? "($($Colors.cyan)$branch$($Colors.white)$change_indicator)" : ""
} catch
{
""
}
}
function shorten_string_to
{
param ([string]$text, [int]$length)
($text.length -gt $length) ? $text.substring(0, $length) : $text
}
function shorten_path
{
param ([string]$path)
$no_home=($path -Replace "$HOME","~")
$segments = ($no_home -split "/")
if ($segments.count -lt 2)
{
return $no_home
}
$init_part = $segments[0..($segments.count - 2)]
$last_part = $segments[($segments.count - 1)]
$cleaned_init = ($init_part | ForEach-Object { shorten_string_to -text $_ -length 5 }) -join "/"
return "$cleaned_init/$last_part"
}
function Prompt
{
$prompt = "╭───$($Colors.cyan)$env:USER"
$prompt += "$($Colors.white) powershelling in "
$prompt += "$($Colors.green)$(shorten_path(Get-Location))$($Colors.white) "
$prompt += prompt_git_status
$prompt += "`n╰─λ "
$prompt
}

View file

@ -0,0 +1,19 @@
if ($host.Name -eq "ConsoleHost")
{
Import-Module PSReadline
Set-PSReadLineKeyHandler -Chord Control+Delete -Function BackwardKillWord
Set-PSReadLineKeyHandler -Chord Control+Backspace -Function BackwardKillWord
Set-PSReadLineKeyHandler -Chord Control+RightArrow -Function NextWord
Set-PSReadLineKeyHandler -Chord Control+LeftArrow -Function BackwardWord
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler Key DownArrow -Function HistorySearchForward
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
Set-PSReadLineKeyHandler -Chord Control+c -Function RevertLine
#Set-PSReadlineKeyHandler -Chord Control+C -Function CancelLine
}
Invoke-Expression (&starship init powershell)

View file

@ -4,6 +4,7 @@ export const device = #{
laptop: SYSTEM.hostname == "thinkix" || SYSTEM.hostname == "frissnix", laptop: SYSTEM.hostname == "thinkix" || SYSTEM.hostname == "frissnix",
linux: SYSTEM.platform == "Linux", linux: SYSTEM.platform == "Linux",
windows: SYSTEM.platform == "Windows",
macbook: "Matthiass-MacBook-Pro" in SYSTEM.hostname, macbook: "Matthiass-MacBook-Pro" in SYSTEM.hostname,
kenbun: "Matthiass-MacBook-Pro" in SYSTEM.hostname, kenbun: "Matthiass-MacBook-Pro" in SYSTEM.hostname,
@ -16,9 +17,9 @@ private fn merge_into_home(enabled, templates) {
} }
export let eggs = #{ export let eggs = #{
"alacritty": #{ targets: "~/.config/alacritty" }, "alacritty": #{ enabled: !device.windows, targets: "~/.config/alacritty" },
"eww": merge_into_home(device.desktop, []), "eww": merge_into_home(device.linux && device.desktop, []),
"eww-bar": merge_into_home(device.desktop, []), "eww-bar": merge_into_home(device.linux && device.desktop, []),
"foot": #{ enabled: device.linux, targets: "~/.config/foot", templates: ["foot.ini"] }, "foot": #{ enabled: device.linux, targets: "~/.config/foot", templates: ["foot.ini"] },
"git": merge_into_home(true, [".gitconfig"]), "git": merge_into_home(true, [".gitconfig"]),
"niri": #{ enabled: device.linux, targets: "~/.config/niri", templates: ["**/*.kdl"] }, "niri": #{ enabled: device.linux, targets: "~/.config/niri", templates: ["**/*.kdl"] },
@ -27,8 +28,8 @@ export let eggs = #{
"starship": merge_into_home(true, []), "starship": merge_into_home(true, []),
"sway": merge_into_home(device.desktop && device.linux, []), "sway": merge_into_home(device.desktop && device.linux, []),
"zed": #{ strategy: "put", targets: "~/.config/zed" }, "zed": #{ enabled: !device.windows, strategy: "put", targets: "~/.config/zed" },
"zsh": merge_into_home(true, []), "zsh": merge_into_home(!device.windows, []),
"rofi": merge_into_home(device.linux, []), "rofi": merge_into_home(device.linux, []),
"gtk": merge_into_home(device.linux, []), "gtk": merge_into_home(device.linux, []),
"scripts": #{ enabled: device.linux, targets: "~/scripts", strategy: "merge" }, "scripts": #{ enabled: device.linux, targets: "~/scripts", strategy: "merge" },
@ -40,7 +41,7 @@ export let eggs = #{
"karabiner": merge_into_home(device.macbook, []), "karabiner": merge_into_home(device.macbook, []),
"sioyek": merge_into_home(device.linux, []), "sioyek": merge_into_home(device.linux, []),
"powershell": merge_into_home(false, []), "powershell": #{ enabled: device.windows, targets: "~/Documents/PowerShell" },
"zathura": merge_into_home(false, []), "zathura": merge_into_home(false, []),
"eww-laptop": merge_into_home(false, []), "eww-laptop": merge_into_home(false, []),
"hyprland": merge_into_home(false, []), "hyprland": merge_into_home(false, []),