From 992c9eb003742016a4884a051d3ef5642d8a474f Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 6 Oct 2024 20:56:38 +0200 Subject: [PATCH] fix alpha, dont print alpha when uneeded --- .config/fish/functions/latex-color.fish | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.config/fish/functions/latex-color.fish b/.config/fish/functions/latex-color.fish index 3e31259..c5328f6 100644 --- a/.config/fish/functions/latex-color.fish +++ b/.config/fish/functions/latex-color.fish @@ -27,17 +27,17 @@ function latex-color --description "Get the LaTeX color from HEX code" # Expand 3 to 4 if test (string length $hex) -eq 3 - set hex $(string join "" $hex 0) + set hex $(string join "" $hex "F") end # Expand 4 to 8 if test (string length $hex) -eq 4 - set hex "$(string replace -ar '(.)' '$1$1' $hex)00" + set hex "$(string replace -ar '(.)' '$1$1' $hex)FF" end # Expand 6 to 8 if test (string length $hex) -eq 6 - set hex $(string join "" $hex 00) + set hex $(string join "" $hex "FF") end # Convert hex to RGB @@ -46,5 +46,10 @@ function latex-color --description "Get the LaTeX color from HEX code" set b (math "0x$(string sub -s 5 -l 2 $hex) / 255") set a (math "0x$(string sub -s 7 -l 2 $hex) / 255") - printf "{%.2f, %.2f, %.2f, %.2f}\n" $r $g $b $a + + if test $a -eq 1 + printf "{%.2f, %.2f, %.2f}\n" $r $g $b + else + printf "{%.2f, %.2f, %.2f, %.2f}\n" $r $g $b $a + end end