oh-my-fish / theme-bobthefish

A Powerline-style, Git-aware fish theme optimized for awesome.
MIT License
1.46k stars 227 forks source link

Invalid index thrown when enabling node #326

Closed TheFern2 closed 2 years ago

TheFern2 commented 2 years ago

I have enabled node on my fish config, but I am getting an error about invalid index. I am running latest fish, version 3.4.1-249-g39df8f0b3, omf 7, and just installed bobthefish today. Tried folders without package.json or nvmrc and same error. Any ideas how to fix it?

set -g theme_display_node yes
~/.local/share/omf/themes/bobthefish/functions/fish_prompt.fish (line 900): Invalid index value
    set -l files $argv[2..]
                          ^
in function '__bobthefish_prompt_find_file_up' with arguments '/home/fernandob package.json .nvmrc .node-version'
        called on line 928 of file ~/.local/share/omf/themes/bobthefish/functions/fish_prompt.fish
in function '__bobthefish_prompt_node'
in function '__fish_prompt_orig'
        called on line 47 of file -
in function 'fish_prompt'
in command substitution
walteraa commented 2 years ago

Same issue here. Did you have luck on this?

TheFern2 commented 2 years ago

I had done a bit of debugging, but I am not great with fish scripting, I figure the index is either out of range or negative when node is activated. I haven't been on my linux machine in a while, but I just turned node prompt off.

bradsheppard commented 2 years ago

Manged to solve this, although I'm still unsure as to the cause.

I tried do a simple echo on the argv list and got the following /home/brad package.json .nvmrc .node-version, which seems correct to me. A simple list with 4 elements. I tried echoing argv[2..] and got the same error mentioned above.

After reading the Fish language docs, it says that argv[2..] is effectively equivalent to argv[2..-1] meaning "from index 2 until the end of the list". Quote from the docs:

A missing starting index in a range defaults to 1. This is allowed if the range is the first index expression of the sequence. Similarly, a missing ending index, defaulting to -1 is allowed for the last index range in the sequence.

Source: https://fishshell.com/docs/current/language.html#expand-index-range

The weird thing though, is if you substitute in argv[2..-1] it seems to work correctly. It seems that the syntax isn't being respected for some reason. I'm not super familiar with Fish language, so if anyone has any thoughts here I'd love to hear them.

bobthecow commented 2 years ago

@bradsheppard That's a great catch, and that's really weird. A simple test case fails on fish 3.1.x for me:

set -l foo 1 2 3 4
echo $foo[2..]
echo $foo[..3]

¯\_(ツ)_/¯

I've pushed a change to add an explicit -1 to the range. Let me know if this resurfaces, all!

TheFern2 commented 2 years ago

Thanks for the fix! I will test when I get a chance.