Microsoft/vscode

Exit code isn't handled correctly in fish shell integration

Open

#169,407 opened on Dec 16, 2022

View on GitHub
 (0 comments) (0 reactions) (1 assignee)TypeScript (10,221 forks)batch import
bughelp wantedterminal-shell-fish

Repository metrics

Stars
 (74,848 stars)
PR merge metrics
 (Avg merge 11h 43m) (1,000 merged PRs in 30d)

Description

@Tyriar The new fish_prompt function does not work properly in my case. My fish configuration uses a right prompt and shows the exit code of the command (green check mark). The exit code is always shown as good, even if the executed program returns a non-0 code. The right prompt is also misaligned. It is one line below where it is supposed to be.

Screenshot from 2022-08-31 12-26-29

https://github.com/microsoft/vscode/blob/8d28ffac6d57b230d74ff00ce1083c5867040902/src/vs/workbench/contrib/terminal/browser/media/shellIntegration.fish#L113-L117

The status code issue seems to be caused by executing __vsc_fish_prompt_start first, because this will overwrite $status and $pipestatus. The misaligned right prompt seems to relate to some newline shenanigans fish does. It removes the last newline from the prompt, but since __vsc_fish_cmd_start is after the prompt it doesn't work any longer. I found these related links: https://github.com/kovidgoyal/kitty/issues/4032, https://github.com/kovidgoyal/kitty/commit/f277cbf3f3fe03cecaec7e619bf8d8970d945dfa

If I change the above snippet to this it seems to work better for me.

    # No fish_mode_prompt, so put everything in fish_prompt.
    function fish_prompt
      set --local prompt (__vsc_fish_prompt)
      __vsc_fish_prompt_start
      if set -q prompt[2]
        builtin printf '%s\n' $prompt[1..-2] # print all but last element of array, each followed by a new line
      end
      builtin printf '%s' $prompt[-1] # print the last component without a newline
      __vsc_fish_cmd_start
    end

Originally reported by @jonasbb at https://github.com/microsoft/vscode/issues/139400#issuecomment-1232759033

Contributor guide