Skip to content

zsh/completion: put compdef on first line#14410

Merged
xokdvium merged 1 commit intoNixOS:masterfrom
bryango:patch-1
Oct 29, 2025
Merged

zsh/completion: put compdef on first line#14410
xokdvium merged 1 commit intoNixOS:masterfrom
bryango:patch-1

Conversation

@bryango
Copy link
Member

@bryango bryango commented Oct 29, 2025

Motivation

Some zsh setups (including mine) do not load the completion if #compdef is not on the first line. So we move the # shellcheck comment to the second line to avoid this issue.

Context

The # shellcheck comment is introduced in 8839bab so cc @fzakaria for comments and review!


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

Some zsh setups (including mine) do not load the
completion if `#compdef` is not on the first line.

So we move the `# shellcheck` comment to the
second line to avoid this issue.
@bryango bryango requested a review from edolstra as a code owner October 29, 2025 10:13
@fzakaria
Copy link
Contributor

Is there a comment or rationale explaining why "some" don't work but others do ?
Might be good to then include as a comment as to why it's not the first line.

@fzakaria
Copy link
Contributor

Ultimately the file is disabled for shellcheck so I don't think it really matters but I personally dislike making changes without knowing why :P

@xokdvium xokdvium added the backport 2.32-maintenance Automatically creates a PR against the branch label Oct 29, 2025
@xokdvium
Copy link
Contributor

Thank you. I was wondering why zsh completions broke

@xokdvium xokdvium added this pull request to the merge queue Oct 29, 2025
Merged via the queue into NixOS:master with commit da637a0 Oct 29, 2025
18 checks passed
@internal-nix-ci
Copy link

Successfully created backport PR for 2.32-maintenance:

@bryango
Copy link
Member Author

bryango commented Oct 29, 2025

Some zsh setups (including mine) do not load the completion if #compdef is not on the first line.

Is there a comment or rationale explaining why "some" don't work but others do ?

I am just saying that at least it broke on my system. Maybe it breaks on everyone else's as well, or maybe it doesn't 😆 It is very hard to track down all the zsh config files (system / user level, .profile or .zshrc etc) that might change how zsh behaves1... And surely I have no understanding of its completion system... Though after some searches I found this in their doc which seems to suggest that it might have been breaking everyone's setup:

When compinit is run, it searches all such files accessible via fpath/FPATH and reads the first line of each of them. This line should contain one of the tags described below. Files whose first line does not start with one of these tags are not considered to be part of the completion system and will not be treated specially.

The tags are:

#compdef ...

https://zsh.sourceforge.io/Doc/Release/Completion-System.html#Autoloaded-files

Footnotes

  1. This can be mitigated by migrating all zsh config to a NixOS/nix-darwin/home-manager module but due to the sheer amout of work, I still haven't done it even after using Nix for several years 😢 my bad

@bryango bryango deleted the patch-1 branch October 29, 2025 17:39
@edolstra edolstra mentioned this pull request Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 2.32-maintenance Automatically creates a PR against the branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants