Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add fish_trace_depth - #12666

#12666
Open
tjkirch wants to merge 1 commit into
fish-shell:masterfish-shell/fish-shell:masterfrom
tjkirch:trace-depthtjkirch/fish-shell:trace-depthCopy head branch name to clipboard
Open

Add fish_trace_depth#12666
tjkirch wants to merge 1 commit into
fish-shell:masterfish-shell/fish-shell:masterfrom
tjkirch:trace-depthtjkirch/fish-shell:trace-depthCopy head branch name to clipboard

Conversation

@tjkirch

@tjkirch tjkirch commented Apr 23, 2026

Copy link
Copy Markdown

This allows limiting the depth to which fish_trace will trace execution. For example, setting it to 0 will only print top-level commands, a value of 1 will print commands inside a for loop from the top level, etc.

Fixes #9069

TODOs:

  • If addressing an issue, a commit message mentions Fixes issue #<issue-number>
  • Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.rst

Comment thread tests/checks/trace.fish

# CHECKERR: > for 1 2
# CHECKERR: -> for a b
# CHECKERR: --> echo 1 a

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is less discoverable than grep, so maybe not worth it

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's simpler and more discoverable in at least two cases:

  1. I'm running a number of commands interactively that I'm trying to understand better, and I don't have to think about how or where to add grep on each one.
  2. I'm writing a script. I want to debug by showing what commands are being run without adding a lot of echos, and I don't want to need exec tricks, extra scopes, or a wrapper script for grep.

In other words, fish_trace_depth is useful in more complex scenarios, which is exactly where you might want fish_trace in the first place.

In both cases, it's helpful to see a level or two of depth, but not the full trace that shows complete function expansions, etc., so it's convenient to have this one obvious setting.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other tests:

  • set the depth based on specific context (e.g. only deep traces for i=2, don't care about i=1 or i=3 so shallow traces)
  • setting a deep depth after going beyond the current max, i.e. a discontinuity in the depth (e.g. start with a depth of 1, then when at the script is a depth 3, set the depth to 4)
  • set the depth in a local scope (variant of the specific context above, but with automatic reset)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nahor I've pushed an update that hopefully addresses your requests. Let me know if I didn't understand and I can adjust.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm writing a script.

I think one alternative is fish_trace=1 fish -c 'echo 123' &| grep -E '^-{0,2}>'

I'm running a number of commands interactively that I'm trying to understand better, and I don't have to think about how or where to add grep on each one.

Hmm maybe interactive shell+terminal is not an ideal environment for this.
Wouldn't it be better to pipe the entire fish_trace into an editor window, and then tell the editor to collapse at a given level.

Not sure yet. Do you have a concrete example where you find this useful?
I've never really filtered the entire output like this but I think I sometimes filter jump between matches of ^--> in the editor or pager.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a concrete example where you find this useful?

Sure. I write a lot of scripts for myself - to manage my system, call other tools, etc. I'm switching to fish because it's a nicer language than bash and I believe in where it's headed. Because the scripts are for myself, I don't need fancy output, but I do want to know what's happening at various points. fish_trace is perfect for this, but it shows way more than is helpful for this case. I don't need to know the complete depth of expansion for every function; for example, the built-in cd function expands to 27 lines of trace, mostly at depths 2 and 3. Setting a trap prints 41 lines down to depth 7. If I can set depth to 0 or 1, I can see the commands I actually wrote, without so many implementation details.

I think one alternative is fish_trace=1 fish -c 'echo 123' &| grep -E '^-{0,2}>'

Sure, and I'm sure there are other clever ways to do it as well, but if I have to wrap scripts to get useful output, it doesn't seem very friendly, and I'm probably not going to do it.

@krobelus krobelus Apr 28, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. For simple scripts, I still use POSIX sh (where set -x; cd won't have noisy output) and for larger ones maybe Python.
Your explanation makes sense.
But this approach seems not quite perfect -- it will not work well if you use lots of if, while and other block statements.
Maybe what you really want is a feature to trace all commands in the current file?
Or if you use separate files for functions, all user-defined functions in ~/.config/fish/functions/ ?
Maybe something like fish_trace=user would make sense.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that fish_trace=user would be nice. I mentioned a similar idea in the linked issue, fish_trace=exec, which would only show external commands that fish runs. I'm sure other filter types could be useful in different cases.

I think that what gets traced is orthogonal to how far it gets traced, and both are useful. I've done the first (admittedly easier) part in this PR, which would solve my current issue, and I'd love to see trace filters in the future as well.

@Nahor Nahor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Full review this time (before it was just a comment on top of my head while I was browsing the pending PRs 😛)

Comment thread tests/checks/trace.fish Outdated
Comment thread src/env_dispatch.rs Outdated
Comment thread src/env_dispatch.rs Outdated
Comment thread tests/checks/trace.fish
Comment thread src/env_dispatch.rs Outdated
Comment thread doc_src/language.rst
@tjkirch
tjkirch force-pushed the trace-depth branch 2 times, most recently from b306f41 to f6f352e Compare April 27, 2026 04:50
Comment thread tests/checks/trace.fish Outdated
Comment thread tests/checks/trace.fish
Comment thread tests/checks/trace.fish Outdated
Comment thread src/env_dispatch.rs Outdated
Comment thread tests/checks/trace.fish
This allows limiting the depth to which fish_trace will trace execution.
For example, setting it to 0 will only print top-level commands, a value
of 1 will print commands inside a for loop from the top level, etc.

Fixes fish-shell#9069
@Nahor

Nahor commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Code looks good. I don't have a particular opinion on the worthiness of the feature though, so I'll refrain from approving.

@ridiculousfish
ridiculousfish self-requested a review May 4, 2026 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Request: Fish Trace depth

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.