Skip to content

feat(completion): add fish shell completion - #15515

Merged
Alizter merged 2 commits into
ocaml:mainfrom
chizy7:fish-completion
Jul 22, 2026
Merged

feat(completion): add fish shell completion#15515
Alizter merged 2 commits into
ocaml:mainfrom
chizy7:fish-completion

Conversation

@chizy7

@chizy7 chizy7 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Description

adds fish to the shells supported by dune completion, folowing the work in #14779 which added bash, zsh, and powershell but left fish out.

Since cmdliner doesnt provide a generic fish completion script (dbuenzli/cmdliner#213), this PR adds one on the Dune side as a new Fish module in bin/completion.ml. It can't live under vendor/cmdliner because that directory is overwritten by vendor/update-cmdliner.sh. The implementation is mostly generic apart from the command name, so it could potentially be upstreamed to cmdliner later.

What's Included

  • Subcommand completion with descriptions.
  • Flag completion and suggestions.
  • Value completion for options like --root=.
  • Filename fallback when Dune has no semantic completions.
  • Support for all completion protocol v1 directives, including restart and message.

What's Not Included

  • Target completion (dune build <TAB>@test, @install, etc.), matching the existing shell implementations.
  • Displaying message directives. Fish has no safe way to show completion messages without interfering with the pager, so they are consumed buut not displayed.

Notes for Reviewers

  • Uses commandline -opc for compatibility with both fish 3.x and 4.x.
  • Shell order is now: bash, zsh, fish, powershell.
  • Tested interactively on fish 4.8.1 on macOS. Testing on other fish versions is welcome.

To try it:

dune completion fish > ~/.config/fish/completions/dune.fish

Related Issue and Motivation

Fish users currently don't get shell completions from dune completion because cmdliner has no fish support. This PR adds a Dune-maintained implementation following the existing completion support, with the possibility of upstreaming it to cmdliner in the future.

Fixes #15334.

Checklist

  • Tests added, if applicable.
  • Change log entry added.
  • Documentation added.

Signed-off-by: Chizaram Chibueze <chizy7@gmail.com>
@chizy7
chizy7 force-pushed the fish-completion branch from 325ec2b to 9211ff9 Compare July 17, 2026 14:53
@Alizter
Alizter requested a review from ElectreAAS July 17, 2026 15:18
@Alizter
Alizter self-requested a review July 17, 2026 15:21
Comment thread bin/completion.ml Outdated
let completion_script ~fun_name =
sprintf
{|function %s
set -l tokens (commandline -opc)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

According to the fish docs -o is deprecated https://fishshell.com/docs/current/cmds/commandline.html. In the changelog they suggest to use -x instead https://fishshell.com/docs/current/relnotes.html#id42

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, I can update it to try -x first and fall back to -o on older fish:

set -l tokens (commandline -xpc 2>/dev/null)
or set tokens (commandline -opc)

Should I keep this fallback, or drop it and require fish >= 4.0?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't use fish personally, so I'll leave that to fish users @ElectreAAS @Leonidas-from-XIV to decide. Since fish isn't the main shell of any distro, I don't think it should be any issue to require a newer version. If people have gone out of their way to setup fish, they are probably able to get their hands on a newer version anyway.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In general I would pick whatever it is that you think would be easier to maintain going forward. If the fallback works then so be it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll keep the fallback then. it's one extra line. I have pushed it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I always just use whatever fish comes with the distribution and would be too lazy to specifically install a newer fish. That said, fish 4.0+ is in a lot of distributions including Debian stable, so I think requesting 4.0+ is ok now and even more ok in the future.

Signed-off-by: Chizaram Chibueze <chizy7@gmail.com>
Comment thread bin/completion.ml

@ElectreAAS ElectreAAS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In the current state of things it works, and everything looks okay at a cursory glance

I'm not a huge fan of adding code that nobody in the team understands, but hopefully we can upstream all of this to cmdliner soon, reducing the maintenance burden on our end

Thanks a lot :)

@Alizter

Alizter commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Thank you very much @chizy7!

@Alizter
Alizter merged commit 301b0b2 into ocaml:main Jul 22, 2026
36 checks passed
@Alizter Alizter added this to the 3.25.0 milestone Jul 23, 2026
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.

fish shell completion

4 participants