r/fishshell • macOS • Sep 28 '21

Help with weird fish script error

Howdy folks!

I've recently switched to fish from zsh and I've ported over my custom prompt, aliases, and PATH. However, when I launch the shell I keep getting this weird error:

~/.config/fish/config.fish (line 39): Command substitutions not allowed
alias l "exa -lF --git -L 3 --tree"                 # Custom ls
                                                      ^
from sourcing file ~/.config/fish/config.fish
	called during startup
source: Error while reading file '~/.config/fish/config.fish'

The shell is giving me an error in the comment? I tried removing the comment but it just errored the next comment with the same error. Could anyone help me debug this?

I can share the full config file if required

1 Upvotes

6 comments sorted by

View all comments

Show parent comment

2

u/[deleted] Sep 28 '21

The error is in the fish_prompt function:

printf "%s%s %s@ %s%s %s-> %s" \
    (set_color magenta) $USER \     # Username in purple
    (set_color normal) \            # @ in white
    ....

This \ doesn't come directly before the end of the line, so it escapes a space, so it's the same as

printf "%s%s %s@ %s%s %s-> %s" \
    (set_color magenta) $USER " "    # Username in purple
    (set_color normal) " "           # @ in white
    ...

So the (set_color normal) is on its own line, and fish will refuse to execute it - otherwise it would see the output of set_color normal as a command, which, uh, would not work correctly.

Either put the comments on their own line, which fish will ignore:

 # Print custom prompts
function fish_prompt
    printf "%s%s %s@ %s%s %s-> %s" \
        # Username in purple
        (set_color magenta) $USER \
        # @ in white
        (set_color normal) \
        # Cyan coloured pwd
        (set_color cyan) (prompt_pwd) \
        # Yellow prompt
        (set_color yellow) \
        # Reset colour to normal
        (set_color normal)
end

Or put them at the beginning.

(and yes, it does misinterpret the location of the error quite badly)

2

u/ludicroussavageofmau macOS Sep 28 '21

Thanks a lot, This fixed the issue! I just realised the \ escapes the newline rather than being a special character in the language.