为什么 argv[-1] 在 fish_title 中显示手册标题?

Why argv[-1] shows the manual title in fish_title?

我正在通过定义 fish_title 函数来自定义终端 windows 中显示的标题。我想在执行 man X 后显示 X,我认为 eval $argv[-1] 会给我那个,但它给了我 man title 本身(例如 FISH(1) fish-shell)。为什么?

我得到了与 (string split " " $argv)[-1] 的实际争论,但我想知道为什么前一次尝试给我带来了意想不到的结果。

I'm customising the title shows in the terminal windows by defining the fish_terminal function.

你的意思是 fish_title 函数。

eval $argv[-1]

这接受最后一个参数并将其作为命令执行。 fish_title 收到的参数是当前命令行。您正在执行的命令是 man X。所以它再次执行 man.

因为通常不支持 multi-line 标题,fish 只会使用 fish_title 输出的第一行作为标题。那是手册页的标题行。


eval 完全是错误的。

您的意思是使用 echo。只需 echo $argv[-1] 给出整个命令行,或 echo (string split " " $argv)[-1] 给出命令行的最后一个字。

并不是说我认为它很有用 - 例如如果你这样做 git diff something.cpp 它会打印 something.cpp,但你这样做了。