It would be great if there would be shell completion for all nix commands, like:
% git a<TAB>
add -- add file contents to index
ai -- alias for 'add -i'
am -- apply patches from a mailbox
ap -- alias for 'add -p'
apply -- apply patch to files and/or to index
archimport -- import an Arch repository into git
archive -- create archive of files from named tree
resources that might be useful:
http://zsh.sourceforge.net/Doc/Release/Completion-Widgets.html#Completion-Widgets
http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-System
http://git.kernel.org/?p=git/git.git;a=blob;f=contrib/completion/git-completion.bash;hb=HEAD
Hi,
Sorry for reviving such an old issue but I started working on zsh completion for Nix commands. I have finished about 99% of the nix-env options. This should be a good reference point for implementing the completion of other commands. I could need some help to implement the options for the other commands and improving existing ones.
Repo is at https://github.com/svenkeidel/nixos-zsh-completion
Best,
Sven
:+1:
I'd _really_ like to have completion for attributes: "nix-env -iA nixos.TAB_TAB" :-)
There is a package for zsh completions now: http://github.com/spwhitt/nix-zsh-completions (nix-env -iA nix-zsh-completions)
Also: https://github.com/spwhitt/nix-zsh-completions/pull/3 (WIP on attribute completions)
The implementation for nix-env at https://github.com/svenkeidel/nixos-zsh-completion seems to be a bit better that the nix-zsh-completion package though. (nix-env -i<tab> is handlet better for instance)
Before someone do it for bash you should now there is interest redesigning the command interface, https://github.com/NixOS/nix/issues/779.
Hopefully not spammy: A working attribute path completion for zsh is at https://github.com/spwhitt/nix-zsh-completions/pull/4
Paths are completed most places where it makes sense. eg. nix-env -i --file local.nix -A, nix-shell '<nixpkgs>' -A, etc.
spwihitt haven't responed yet, but I've used it for a while myself without major problems. It would be nice if someone wanted to test it to weed out possible bugs before it's (hopefully) merged.
New version of nix-zsh-completions (with attribute path completion) is now in master: https://github.com/NixOS/nixpkgs/pull/21331
@hedning have implemented completions for bash too (including the new nix commands): https://github.com/NixOS/nix/issues/1658#issuecomment-343415285
(ref #1658)
This is done now, no? Suggest close.
From 18.03 and forward nix-bash-completions will be installed when programs.bash.enableCompletion is turned on, so I'd also suggest closing this.
There's a question of how to make completion work out of the box when using Nix on non-NixOS systems, but that's another issue.
Most helpful comment
Hi,
Sorry for reviving such an old issue but I started working on zsh completion for Nix commands. I have finished about 99% of the
nix-envoptions. This should be a good reference point for implementing the completion of other commands. I could need some help to implement the options for the other commands and improving existing ones.Repo is at https://github.com/svenkeidel/nixos-zsh-completion
Best,
Sven