- install fish, version 3.5.1
cp /usr/share/fish/tools/web_config/sample_prompts/disco.fish ~/.config/fish/functions/fish_prompt.fish
mkdir -p /home/tocic/backup
cd /home/tocic/backup
Expected behaviour
Colorize the directory.
Actual behaviour
math: Error: Unknown function
'0.2126 x 0x52 + 0.7152 x 0x6b + 0.0722 x'
^
test: Missing argument at index 3
-lt 120
^
~/.config/fish/functions/fish_prompt.fish (line 27):
while test (math 0.2126 x $col[1] + 0.7152 x $col[2] + 0.0722 x $col[3]) -lt 120
^
in function 'fish_prompt'
in command substitution
set_color: Unknown color “526b”
Notes
The problem is that math --base=hex returns 0x526b3 for that specific path. The value can't be splitted using string match -ra .. as 3 bytes 05, 26, b3. Actually it returns just 2 52 and 6b, so $col[3] is undefined and results in the error.
The simplest solution (as far as I can tell) is to add string pad -c 0 -w 8 -r after string sub -s 3 (right padding to preserve the previous behaviour of using 0x$shas[1..3] instead of 0x$shas[2..4]; 8 because cksum uses CRC32 by default). Now we can also remove the further string pad -c 0 -w 2 call.
But with this code it's still impossible to disambiguate paths with checksums 0x526b301 and 0x526b302 because the least significant byte doesn't participate in color selection. So I think the best solution is to correctly pad the checksum (using string pad -c 0 -w 8 instead of right padding or using xargs printf '%08x' instead of math --base=hex | string sub -s 3), split it into 4 bytes and somehow use all of them to generate a color.
cp /usr/share/fish/tools/web_config/sample_prompts/disco.fish ~/.config/fish/functions/fish_prompt.fishmkdir -p /home/tocic/backupcd /home/tocic/backupExpected behaviour
Colorize the directory.
Actual behaviour
Notes
The problem is that
math --base=hexreturns0x526b3for that specific path. The value can't be splitted usingstring match -ra ..as 3 bytes05,26,b3. Actually it returns just 252and6b, so$col[3]is undefined and results in the error.The simplest solution (as far as I can tell) is to add
string pad -c 0 -w 8 -rafterstring sub -s 3(right padding to preserve the previous behaviour of using0x$shas[1..3]instead of0x$shas[2..4]; 8 becausecksumuses CRC32 by default). Now we can also remove the furtherstring pad -c 0 -w 2call.But with this code it's still impossible to disambiguate paths with checksums
0x526b301and0x526b302because the least significant byte doesn't participate in color selection. So I think the best solution is to correctly pad the checksum (usingstring pad -c 0 -w 8instead of right padding or usingxargs printf '%08x'instead ofmath --base=hex | string sub -s 3), split it into 4 bytes and somehow use all of them to generate a color.