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
This commit is contained in:
Fabian Boehm 2022-08-27 16:37:32 +02:00
parent 227e1f6300
commit 07b2f1054b

View file

@ -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.