repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by admin
nugu/linux_console.nu
Rawuse palette.nu
# Generate a sudo-free Linux virtual console palette script.
# Linux console supports 16 palette slots via OSC: ESC ] P nrrggbb.
# It does not provide real truecolor; SGR 256/24-bit colors are mapped back.
export def theme [mode: string] {
let nugu = (palette nugu $mode)
let p = $nugu.palette
let colors = [
$p.content.backdrop # 0: black/default background
$p.error # 1: red
$p.content.focus # 2: green
$p.warning # 3: yellow/brown
$p.content.important_local # 4: blue
$p.content.accent # 5: magenta
$p.content.unfocus # 6: cyan
$p.content.normal # 7: white/default foreground
$p.content.minor # 8: bright black
$p.info # 9: bright red
$p.ui.unfocus # 10: bright green
$p.ui.backdrop # 11: bright yellow
$p.content.important_global # 12: bright blue
$p.ui.accent # 13: bright magenta
$p.ui.important_local # 14: bright cyan
$p.ui.important_global # 15: bright white
]
let palette_lines = ($colors | enumerate | each {|e|
$"printf '\\033]P(hex-index $e.index)(strip-hash $e.item)'"
})
let header = [
"#!/bin/sh"
"# Generated by nugu/linux_console.nu."
"# Sudo-free Linux virtual console palette."
"# No effect outside TERM=linux."
""
"if [ \"${TERM:-}\" != linux ]; then"
"\treturn 0 2>/dev/null || exit 0"
"fi"
""
$"export NUGU_CONSOLE_THEME=($mode)"
""
]
let footer = [
""
"# After palette rewrite, black=slot 0 and white=slot 7."
"if command -v setterm >/dev/null 2>&1; then"
"\tsetterm --foreground white --background black --store"
"fi"
""
]
($header ++ $palette_lines ++ $footer) | str join "\n"
}
def strip-hash [hex: string] {
$hex | str trim | str replace --regex '^#' '' | str lowercase
}
def hex-index [index: int] {
[
"0"
"1"
"2"
"3"
"4"
"5"
"6"
"7"
"8"
"9"
"a"
"b"
"c"
"d"
"e"
"f"
] | get $index
}