Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tocic opened this issue Aug 27, 2022 · 1 comment
Closed

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

tocic opened this issue Aug 27, 2022 · 1 comment
Labels
bug Something that's not working as intended
Milestone

Comments

@tocic
Copy link
Contributor

tocic commented Aug 27, 2022

  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.

@faho faho closed this as completed in 07b2f10 Aug 27, 2022
@faho faho added the bug Something that's not working as intended label Aug 27, 2022
@faho faho added this to the fish 3.6.0 milestone Aug 27, 2022
@faho
Copy link
Member

faho commented Aug 27, 2022

Sure, done.

Using string pad is least odious. xargs in particular is an external tool and tbh terribly overused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that's not working as intended
Projects
None yet
Development

No branches or pull requests

2 participants