Skip to content

Fix: correct function and variable naming in fish completion script#2286

Open
TimSoethout wants to merge 1 commit intourfave:mainfrom
TimSoethout:fix/fish-dynamic-completions
Open

Fix: correct function and variable naming in fish completion script#2286
TimSoethout wants to merge 1 commit intourfave:mainfrom
TimSoethout:fix/fish-dynamic-completions

Conversation

@TimSoethout
Copy link
Contributor

@TimSoethout TimSoethout commented Mar 19, 2026

This pull request updates the Fish shell autocomplete script to fix formatting and variable substitution issues, ensuring correct function naming and output formatting for command completions.

Improvements to autocomplete script:

  • Renamed function and completion commands to use %[1]s instead of %[1], ensuring proper variable substitution for command names throughout the script (autocomplete/fish_autocomplete). [1] [2]
  • Updated string matching and printf formatting to use the correct Fish and printf syntax, preventing formatting errors in completion output (autocomplete/fish_autocomplete).

What type of PR is this?

  • bug

What this PR does / why we need it:

PR #2270 introduced dynamic fish completions but used invalid Go format specifiers in the fish autocomplete template. The format string %[1] was missing the type specifier s, causing fmt.Sprintf to produce malformed output like __%!_(string=appname)perform_completion instead of __appname_perform_completion.

Changes:

  • autocomplete/fish_autocomplete: Fixed format specifiers from %[1] to %[1]s (7 occurrences). Also escaped %s as %%s in the printf statements so they remain literal in the generated fish script.

Which issue(s) this PR fixes:

Fixes #2285

Testing

  • All existing tests pass
  • New regression test TestCompletionFishFormat added
  • Manually tested on fish 4.5.0:
./app completion fish | source # Sources without error
functions __app_perform_completion # Function exists
complete -c app # Completions registered

Release Notes

Fixed fish shell completion script generation that was broken due to invalid format specifiers (introduced in v3.7.0)

@TimSoethout assisted by copilot.

Copilot AI review requested due to automatic review settings March 19, 2026 10:20
@TimSoethout TimSoethout requested a review from a team as a code owner March 19, 2026 10:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes formatting issues in the Fish shell completion script template used by cli completion fish, correcting Go fmt.Sprintf placeholder usage so generated Fish functions/completions render with the expected command name and without %!-style formatting errors.

Changes:

  • Updated Fish completion template placeholders from %[1] to %[1]s for correct Go string substitution.
  • Escaped printf format verbs (%s%%s) so they remain literal in the generated Fish script.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +3 to 5
function __%[1]s_perform_completion
# Extract all args except the last one
set -l args (commandline -opc)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not committed, not adding much

Copy link
Contributor

Choose a reason for hiding this comment

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

@TimSoethout Can you add or update an existing test case for this ?

Copy link
Contributor Author

@TimSoethout TimSoethout Mar 19, 2026

Choose a reason for hiding this comment

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

I had a testcase, but it didn't make much sense. It was more of a regression test which specifically pattern matched on the specific wrong/correct output syntax of the earlier bug/error.

There was no test in place before, so left it as is.

WDYT would make a valuable test case?
Ideally actually having fish source the output without errors, but not sure if we want to go that far?

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.

Dynamic fish completions breaks fish completions

3 participants