是否有 POSIX shell 的等效项set -x
或set -o xtrace
导致 shell 显示正在fish
shell 中运行的命令?
答案1
从 Fish 3.1.0 开始,该fish_trace
变量使此功能可用:
> set fish_trace on; isatty; set -e fish_trace
++ source share/fish/functions/isatty.fish
++++ function isatty -d 'Tests if a file descriptor is a tty'
+ isatty
+++ set -l options h/help
+++ argparse -n isatty h/help --
+++ if
+++ set -q _flag_help
+++ end if
+++ if
+++ set -q 'argv[2]'
+++ end if
+++ set -l fd
++++ set fd 0
+++ '[' -t 0 ']'
+ set -e fish_trace
跟踪输出的位置由--debug-output
Fish 进程的选项控制。
在fish 3.1.0之前,您可以使用fish -p some_trace_file
运行一个fish会话来将配置文件输出到“some_trace_file”,这可以达到几乎相同的效果(有一些缺点 - 请参阅下面的评论)。
答案2
我能看到的最接近的东西,类似于set -o xtrace
in zsh
,通过fish
使用-d 4
or调用--debug-level=4
:
$ fish -d 4 -c 'echo 1'
fish: Exec job 'builtin source /usr/share/fish/config.fish 2>/dev/null' with id 1
fish: Exec job 'set -g IFS \n\ \t' with id 2
fish: Set status of set -g IFS \n\ \t to 0 using short circuit
fish: Job is constructed
fish: Continue job 2, gid 0 (set -g IFS \n\ \t), COMPLETED, NON-INTERACTIVE
...
fish: Exec job 'echo 1' with id 1
1
fish: Set status of echo 1 to 0 using short circuit
fish: Job is constructed
fish: Continue job 1, gid 0 (echo 1), COMPLETED, NON-INTERACTIVE