【发布时间】:2020-09-16 08:12:02
【问题描述】:
有时当我在终端上工作时,[SIGINT] 会出现在我的插入符号之前。
- 这是什么意思?
- 为什么输入
ls会删除该标记?
环境
我使用的是 Ubuntu 20.04,运行 fish 作为我的 shell。
【问题讨论】:
有时当我在终端上工作时,[SIGINT] 会出现在我的插入符号之前。
ls 会删除该标记?环境
我使用的是 Ubuntu 20.04,运行 fish 作为我的 shell。
【问题讨论】:
这意味着你开始的最后一件事因收到 SIGINT 信号而被终止,这通常是当你按 ctrl-c 时发生的。
运行ls 会删除它,因为 ls 只是运行到完成,所以现在最后的东西没有被信号杀死。
Fish 的默认提示会显示此信息,因为它很有用,例如如果程序崩溃,它将显示 SIGABRT 或类似的信息。
要删除它,您可以使用fish_config 从示例中选择一个没有它的提示,或者通过修改fish_prompt 函数来制作您自己的提示,例如通过
funced fish_prompt
# try it out, once you are happy run
funcsave fish_prompt
【讨论】:
如果是bash,我会说有人配置了bash 函数以在生成提示时运行。您可以使用PS1 环境变量做各种美妙的事情。但是,正如您所说,您使用 fish 作为您的外壳,所以它不是 PS1 环境变量。
这似乎是fish 中的标准行为,至少在未修改的Ubuntu 20.04 下,如以下记录所示,其中我 CTRL-C @ 987654328@命令:
pax@paxbox ~> sleep 3600 # will ctrl-c this.
^C
pax@paxbox ~ [SIGINT]> true # successful exit.
pax@paxbox ~> false # failed exit.
pax@paxbox ~ [1]>
pax@paxbox ~ [1]> fish -c 'exit 42' # arbitrary exit value.
pax@paxbox ~ [42]>
您可以通过查看functions fish_prompt 的输出来了解为什么它会这样做,因为这是在该 shell 中被调用以生成提示的函数:
# Defined in /usr/share/fish/functions/fish_prompt.fish @ line 4
function fish_prompt --description 'Write out the prompt'
set -l last_pipestatus $pipestatus
set -l normal (set_color normal)
# Color the prompt differently when we're root
set -l color_cwd $fish_color_cwd
set -l prefix
set -l suffix '>'
if contains -- $USER root toor
if set -q fish_color_cwd_root
set color_cwd $fish_color_cwd_root
end
set suffix '#'
end
# If we're running via SSH, change the host color.
set -l color_host $fish_color_host
if set -q SSH_TTY
set color_host $fish_color_host_remote
end
# Write pipestatus
set -l prompt_status (__fish_print_pipestatus " [" "]" "|" (set_color $fish_color_status) (set_color --bold $fish_color_status) $last_pipestatus)
echo -n -s (set_color $fish_color_user) "$USER" $normal @ (set_color $color_host) (prompt_hostname) $normal ' ' (set_color $color_cwd) (prompt_pwd) $normal (fish_vcs_prompt) $normal $prompt_status $suffix " "
end
接近末尾的行设置prompt_status,将[SIGINT] 添加到正在输出的提示中,此时最后一个命令被中断(或添加任何非零退出代码以正常完成)。
如果您想更改该函数的行为,您可以制作自己的副本:
mkdir -p ~/.config/fish/functions
function fish_prompt >? ~/.config/fish/functions/fish_prompt.fish
然后进行任何你想要的改变。
【讨论】: