From 07b2f1054bfa42b67ca5d132e2320e620daa0fb3 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Sat, 27 Aug 2022 16:37:32 +0200 Subject: [PATCH] disco prompt: Pad hash It's possible cksum returns less than 3 full bytes, so let's just turn the ones we don't get into 0 Fixes #9164 --- share/tools/web_config/sample_prompts/disco.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/tools/web_config/sample_prompts/disco.fish b/share/tools/web_config/sample_prompts/disco.fish index a9fe94764..6d981bb56 100644 --- a/share/tools/web_config/sample_prompts/disco.fish +++ b/share/tools/web_config/sample_prompts/disco.fish @@ -19,7 +19,7 @@ function fish_prompt # We hash the physical PWD and turn that into a color. That means directories (usually) get different colors, # but every directory always gets the same color. It's deterministic. # We use cksum because 1. it's fast, 2. it's in POSIX, so it should be available everywhere. - set -l shas (pwd -P | cksum | string split -f1 ' ' | math --base=hex | string sub -s 3 | string match -ra ..) + set -l shas (pwd -P | cksum | string split -f1 ' ' | math --base=hex | string sub -s 3 | string pad -c 0 -w 6 | string match -ra ..) set -l col 0x$shas[1..3] # If the (simplified idea of) luminance is below 120 (out of 255), add some more.