Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a zsh completion script #4128

Merged
merged 2 commits into from Oct 9, 2020
Merged

Conversation

thufschmitt
Copy link
Member

Extends the completion mechanism to also output the descriptions, and add a zsh completion script taking advantage of this.

This is a breaking change for the existing bash completion script (which can cause some minor issues if one updates the Nix client but not the script), but afaik it hasn't made it to any release yet, so it shouldn't be a major issue.

The current implementation also has an issue if the word to complete has a tab in it, but that sounds unlikely-enough to happen in practice

Make nix output completions in the form `completion\tdescription`.
This can't be used by bash (afaik), but other shells like zsh or fish
can display it along the completion choices
Based on @clhodapp's suggestion in nix-community/nix-zsh-completions#32 (comment) and adapted to use the description of the completions
@@ -17,8 +17,19 @@ void Args::addFlag(Flag && flag_)
if (flag->shortName) shortFlags[flag->shortName] = flag;
}

void Completions::add(std::string completion, std::string description)
{
insert(Completion{
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add an assert here to check that description doesn't contain a newline.

@edolstra edolstra merged commit ea4b2b9 into NixOS:master Oct 9, 2020
@edolstra edolstra deleted the extended-completions branch October 9, 2020 20:02
@matthewbauer
Copy link
Member

Could you add a local.mk file like:

$(eval $(call install-file-as, $(d)/completion.zsh, $(datarootdir)/zsh/site-functions/_nix, 0644))

so it's picked up by zsh fpath?

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.

None yet

3 participants