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

Add a zsh completion script #4128

merged 2 commits into from Oct 9, 2020

Conversation

@regnat
Copy link
Contributor

@regnat regnat commented Oct 9, 2020

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

regnat added 2 commits Oct 9, 2020
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 spwhitt/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

@edolstra edolstra Oct 9, 2020

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
2 checks passed
@edolstra edolstra deleted the extended-completions branch Oct 9, 2020
@matthewbauer
Copy link
Member

@matthewbauer matthewbauer commented Oct 10, 2020

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
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants