xtrace equivalent in the fish shell

The closest thing I can see, similar to set -o xtrace in zsh, by calling fish with -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

Since fish 3.1.0, the fish_trace variable makes this functionality available:

> 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

The location of the trace output is controlled by the --debug-output option to the fish process.

Before fish 3.1.0, you can use fish -p some_trace_file to run a fish session which outputs a profile to "some_trace_file", which can achieve almost the same effect (with some disadvantages - see the comments below).

Tags:

Debugging

Fish