Microsoft/vscode

Exit code isn't handled correctly in fish shell integration

Open

#169,407 创建于 2022年12月16日

在 GitHub 查看
 (0 评论) (0 反应) (1 负责人)TypeScript (10,221 fork)batch import
bughelp wantedterminal-shell-fish

仓库指标

Star
 (74,848 star)
PR 合并指标
 (平均合并 11小时 43分钟) (30 天内合并 1,000 个 PR)

描述

@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

贡献者指南