diff options
| -rw-r--r-- | nixos/hosts/box/box.nix | 223 |
1 files changed, 1 insertions, 222 deletions
diff --git a/nixos/hosts/box/box.nix b/nixos/hosts/box/box.nix index 7c5a382..b419a71 100644 --- a/nixos/hosts/box/box.nix +++ b/nixos/hosts/box/box.nix @@ -5,6 +5,7 @@ ../../mdls/hypr.nix ../../mdls/qksh.nix ../../mdls/vim.nix + ../../mdls/cls.nix ]; home.username = "cat"; @@ -199,228 +200,6 @@ ''; }; - home.packages = [ - (pkgs.writeShellScriptBin "cls" '' - [ -z "$1" ] && echo "usage: cls <image>" >&2 && exit 1 - [ ! -f "$1" ] && echo "cls: file not found: $1" >&2 && exit 1 - - cls="$HOME/.cls" - mkdir -p "$cls" - - awww_out=$(awww img -o HDMI-A-1 "$1" --transition-type grow --transition-duration 1.5 --transition-fps 120 2>&1) - [ $? -ne 0 ] && echo "cls: awww: $awww_out" >&2 - awww clear --outputs DP-1 2>/dev/null - - raw=$(magick "$1" -thumbnail 50x50^ -colors 8 -unique-colors txt:- 2>&1) - - base=$(printf '%s\n' "$raw" \ - | grep -oE '#[0-9A-Fa-f]{6}' \ - | awk '{ - r = strtonum("0x" substr($0,2,2)) - g = strtonum("0x" substr($0,4,2)) - b = strtonum("0x" substr($0,6,2)) - printf "%d %s\n", int(0.299*r + 0.587*g + 0.114*b), $0 - }' \ - | sort -n \ - | awk '{print $2}' \ - | head -8) - - [ -z "$base" ] && echo "cls: magick failed" >&2 && echo "$raw" >&2 && exit 1 - - n=$(printf '%s\n' "$base" | wc -l) - last=$(printf '%s\n' "$base" | tail -1) - while [ "$n" -lt 8 ]; - do - base=$(printf '%s\n%s' "$base" "$last") - n=$((n+1)) - done - - bright=$(printf '%s\n' "$base" | awk '{ - r = strtonum("0x" substr($0,2,2)) - g = strtonum("0x" substr($0,4,2)) - b = strtonum("0x" substr($0,6,2)) - r = int(r*1.4); if (r>255) r=255 - g = int(g*1.4); if (g>255) g=255 - b = int(b*1.4); if (b>255) b=255 - printf "#%02X%02X%02X\n", r, g, b - }') - - cols=$(printf '%s\n%s' "$base" "$bright") - - c0=$(printf '%s\n' "$cols" | sed -n '1p') - c1=$(printf '%s\n' "$cols" | sed -n '2p') - c2=$(printf '%s\n' "$cols" | sed -n '3p') - c3=$(printf '%s\n' "$cols" | sed -n '4p') - c4=$(printf '%s\n' "$cols" | sed -n '5p') - c5=$(printf '%s\n' "$cols" | sed -n '6p') - c6=$(printf '%s\n' "$cols" | sed -n '7p') - c7=$(printf '%s\n' "$cols" | sed -n '8p') - c8=$(printf '%s\n' "$cols" | sed -n '9p') - c9=$(printf '%s\n' "$cols" | sed -n '10p') - c10=$(printf '%s\n' "$cols" | sed -n '11p') - c11=$(printf '%s\n' "$cols" | sed -n '12p') - c12=$(printf '%s\n' "$cols" | sed -n '13p') - c13=$(printf '%s\n' "$cols" | sed -n '14p') - c14=$(printf '%s\n' "$cols" | sed -n '15p') - c15=$(printf '%s\n' "$cols" | sed -n '16p') - - bg="$c0" - fg=$(printf '%s\n' "$cols" | awk -v bg="$c0" ' - function lum(hex, r,g,b,rs,gs,bs) { - r = strtonum("0x" substr(hex,2,2)) / 255 - g = strtonum("0x" substr(hex,4,2)) / 255 - b = strtonum("0x" substr(hex,6,2)) / 255 - rs = (r<=0.04045) ? r/12.92 : ((r+0.055)/1.055)^2.4 - gs = (g<=0.04045) ? g/12.92 : ((g+0.055)/1.055)^2.4 - bs = (b<=0.04045) ? b/12.92 : ((b+0.055)/1.055)^2.4 - return 0.2126*rs + 0.7152*gs + 0.0722*bs - } - function contrast(a,b, l1,l2,t) { - l1 = lum(a); l2 = lum(b) - if (l1 < l2) { t=l1; l1=l2; l2=t } - return (l1+0.05) / (l2+0.05) - } - BEGIN { best=""; bestc=0 } - { - c = contrast($0, bg) - if (c > bestc) { bestc=c; best=$0 } - } - END { print best } - ') - cursor="$fg" - - printf '%s' "$1" > "$cls/cls" - - printf '%s\n' "$cols" | awk '{printf "color%d=\"%s\"\n", NR-1, $0}' > "$cls/cls.sh" - printf 'background="%s"\nforeground="%s"\ncursor="%s"\n' "$bg" "$fg" "$cursor" >> "$cls/cls.sh" - - cat > "$cls/cls.json" << ENDJSON - { - "wallpaper": "$1", - "alpha": "100", - "special": { - "background": "$bg", - "foreground": "$fg", - "cursor": "$cursor" - }, - "colors": { - "color0": "$c0", - "color1": "$c1", - "color2": "$c2", - "color3": "$c3", - "color4": "$c4", - "color5": "$c5", - "color6": "$c6", - "color7": "$c7", - "color8": "$c8", - "color9": "$c9", - "color10": "$c10", - "color11": "$c11", - "color12": "$c12", - "color13": "$c13", - "color14": "$c14", - "color15": "$c15" - } - } - ENDJSON - - printf '%s\n' "$cols" > "$cls/colors.txt" - - cat > "$cls/kitty.conf" << ENDKITTY - foreground $fg - background $bg - background_opacity 1.0 - cursor $cursor - - active_tab_foreground $bg - active_tab_background $fg - inactive_tab_foreground $fg - inactive_tab_background $bg - - active_border_color $fg - inactive_border_color $bg - bell_border_color $c1 - - color0 $c0 - color8 $c8 - color1 $c1 - color9 $c9 - color2 $c2 - color10 $c10 - color3 $c3 - color11 $c11 - color4 $c4 - color12 $c12 - color5 $c5 - color13 $c13 - color6 $c6 - color14 $c14 - color7 $c7 - color15 $c15 - ENDKITTY - - cat > "$cls/colors.fish" << ENDFISH - set fish_color_autosuggestion ''${c8#?} - set fish_color_cancel ''${c1#?} '--reverse' - set fish_color_command ''${c10#?} - set fish_color_comment ''${c8#?} - set fish_color_cwd ''${c2#?} - set fish_color_cwd_root ''${c1#?} - set fish_color_end ''${c3#?} - set fish_color_error ''${c1#?} - set fish_color_escape ''${c5#?} - set fish_color_history_current --bold - set fish_color_host ''${c12#?} - set fish_color_host_remote ''${c12#?} - set fish_color_keyword ''${c5#?} - set fish_color_match --background=''${c4#?} - set fish_color_normal ''${fg#?} - set fish_color_operator ''${c6#?} - set fish_color_option ''${c3#?} - set fish_color_param ''${c12#?} - set fish_color_quote ''${c11#?} - set fish_color_redirection ''${c5#?} - set fish_color_search_match --background=''${c8#?} - set fish_color_selection --background=''${c8#?} - set fish_color_status ''${c1#?} - set fish_color_user ''${c10#?} - set fish_color_valid_path --underline - set fish_pager_color_background ''${bg#?} - set fish_pager_color_completion ''${fg#?} - set fish_pager_color_description ''${c8#?} - set fish_pager_color_prefix ''${c10#?} - set fish_pager_color_progress ''${c8#?} - set fish_pager_color_secondary_background ''${bg#?} - set fish_pager_color_secondary_completion ''${fg#?} - set fish_pager_color_secondary_description ''${c8#?} - set fish_pager_color_secondary_prefix ''${c10#?} - set fish_pager_color_selected_background --background=''${c8#?} - set fish_pager_color_selected_completion ''${fg#?} - set fish_pager_color_selected_description ''${c8#?} - set fish_pager_color_selected_prefix ''${c10#?} - ENDFISH - - { - printf '%s\n' "$cols" | awk '{printf "\033]4;%d;%s\007", NR-1, $0}' - printf '\033]10;%s\007' "$fg" - printf '\033]11;%s\007' "$bg" - printf '\033]12;%s\007' "$cursor" - } > "$cls/sequences" - - for pty in /proc/*/fd/0; - do - [ -c "$pty" ] && [ -w "$pty" ] && cat "$cls/sequences" > "$pty" 2>/dev/null - done - - printf '%s\n' "$base" | awk '{ - r = strtonum("0x" substr($0,2,2)) - g = strtonum("0x" substr($0,4,2)) - b = strtonum("0x" substr($0,6,2)) - printf "\033[48;2;%d;%d;%dm \033[0m %s\n", r, g, b, $0 - }' - '') - ]; - home.file = { ".documents/obsidian/.obsidian/app.json".text = builtins.toJSON { readableLineLength = true; |
