Xtrace equivalent in the fish shell

debuggingfish

Is there an equivalent of POSIX shells' set -x or set -o xtrace that cause the shell to display the commands being run in the fish shell?

Best Answer

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).

Related Question