Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion invoke/completion/complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,15 @@ def print_completion_script(shell: str, names: List[str]) -> None:
binary = names[0]
with open(path, "r") as script:
print(
script.read().format(binary=binary, spaced_names=" ".join(names))
script.read().format(
binary=binary,
spaced_names=" ".join(names),
# Fish escapes backslashes and quotes in single-quoted names.
fish_commands=" ".join(
"--command '{}'".format(
name.replace("\\", "\\\\").replace("'", "\\'")
)
for name in names
),
)
)
3 changes: 1 addition & 2 deletions invoke/completion/fish.completion
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ function __complete_{binary}
end

# --no-files: Don't complete files unless invoke gives an empty result
# TODO: find a way to honor all binary_names
complete --command {binary} --no-files --arguments '(__complete_{binary})'
complete {fish_commands} --no-files --arguments '(__complete_{binary})'
9 changes: 5 additions & 4 deletions sites/docs/invoke.rst
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,11 @@ your needs, where the program is installed, and your shell:
But again, this is entirely up to you and your shell.

.. note::
If you're using ``fish``, you *must* use this tactic, as our fish
completion script is not suitable for direct sourcing. Fish shell users
should direct the output of the command to a file in the
``~/.config/fish/completions/`` directory.
Fish loads completions from a file named after the command. Save the
script as ``invoke.fish`` in ``~/.config/fish/completions/`` to enable
autoloading for ``invoke``. To autoload completions for ``inv``, make
the same script available in that directory as ``inv.fish``, for example
by symlinking it to ``invoke.fish``.

- Finally, if your copy of the needing-completion program is only installed in
a specific environment like a virtualenv, you can use either of the above
Expand Down
2 changes: 2 additions & 0 deletions sites/www/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Changelog
=========

- :bug:`1036` Register all configured command names in generated Fish
completions, including ``inv``. Thanks to Techcable for the report.
- :release:`3.0.3 <2026-04-07>`
- :support:`- backported` Reverted the `@task
<invoke.tasks.task>` return value type hint change; it actually just makes
Expand Down
15 changes: 14 additions & 1 deletion tests/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,20 @@ def fish_works(self):
"someappname --print-completion-script fish", invoke=False
)
assert "function __complete_someappname" in out
assert "complete --command someappname" in out
assert "complete --command 'someappname'" in out

def fish_registers_aliases(self):
out, err = expect(
"someappname --print-completion-script fish",
program=Program(
binary_names=["someappname", "shorterapp", "literal\\", "it's"]
),
invoke=False,
)
assert (
r"complete --command 'someappname' --command 'shorterapp'"
r" --command 'literal\\' --command 'it\'s' " in out
)


class ShellCompletion:
Expand Down