Skip to content

Disco prompt produces "Unknown function" error for some paths #9164

Description

@tocic
  1. install fish, version 3.5.1
  2. cp /usr/share/fish/tools/web_config/sample_prompts/disco.fish ~/.config/fish/functions/fish_prompt.fish
  3. mkdir -p /home/tocic/backup
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething that's not working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions