Closed Ma27 closed 3 years ago
Found a solution that's backwards compatible:
local arg_text=${option_spec##*-[a-z-]# }
local opt_text=${option_spec%%$arg_text}
local -a option_args=(${=arg_text//[^A-Z-[:space:]]/})
local -a option_group=(${=opt_text//,/})
For normal arguments this works (though we should really preserve any ?
and handle those):
local -a args=(${=help[1]//(*FLAGS|[^A-Z ])/})
Now I'm getting a weird rendering issue, where the prompt blanks while waiting for completions. Not sure if that's reproducable or not though.
Found a solution that's backwards compatible:
Nice! I decided to focus on a POC for Nix 2.4 first before taking care of backwards compatibility, but this is something that really has to be fixed :+1: .
Now I'm getting a weird rendering issue
Same here. I'll try to fix this tomorrow. I also have a basic POC for flakes and registries as well, so with the next changes I'll push here, we'll hopefully have something usable to test and review :)
Have basic support for nix-flake references now. Please note that this may contain bugs and is not ready yet as I'm not aware (yet) of all semantics of the new nix
2.4 CLI API.
For dogfooding, I'll use my git branch for my local shell now to catch some regressions.
Been testing this out for a few hours now, and it looks very good so far. I'm using flakes and experimental CLI, so far without any issues, in my default shell. :+1:
nix flake
-subcommands get completed now as well. Not the prettiest change though, we may want to find a better approach lateron :)
Tested as well, looks good, assuming that I should not expect flags to update all the way down right now (eg. nix flake update --<tab>
That's right, unfortunately I didn't find an obvious way to fix it right now, but I'll work on this soon :)
Just pushed a change that treats nested commands in a better way by getting rid of the gross $subcmd
hack. This solves issues like missing options for nix flake foobar
and now it's also possible to complete the actual arguments for e.g. nix flake info
.
Please note that I'm not a seasoned ZSH hacker so I had to use grep
and sed
on a few occasions, suggestions for improvements are welcome though.
In order to keep this somehow understandable I added a few comments explaining what's happening now.
I'll dogfood the change now, however it took me a while to get this together, so I wouldn't be too surprised if this causes a few new regressions.
@srhb @hedning while this isn't backwards-compatible (yet) and there are still a few things missing, I'd say that this slowly reaches a usable state and can be reviewed :)
AFAICS the basic functionality is now implemented. Before discussing things like backwards-compat etc. I'd love to get some feedback regarding functionality and implementation :)
FYI it may be better to use NIX_GET_COMPLETIONS
(see #32 for that). If that's actually the case we can close this. Too bad I didn't know about it before ^^
Today I noticed this is missing:
diff --git i/_nixos-rebuild w/_nixos-rebuild
index 3586f24..d30fa71 100644
--- i/_nixos-rebuild
+++ w/_nixos-rebuild
@@ -20,6 +20,7 @@ _arguments \
'--upgrade[Fetch the latest version of NixOS from the NixOS channel]'\
'--install-bootloader[(Re)install bootloader on the configured device]'\
"--no-build-nix[Don't build Nix package manager]"\
+ '--update-input[Update the given flake input (usually "nixpkgs"):flake input:'
'--fast[Equivalent to --no-build-nix --show-trace]'\
'--rollback[Roll back to the previous configuration]'\
'(--profile-name -p)'{--profile-name,-p}'[Profile to use to track current and previous system configurations]:Profile:_nix_profiles'\
Along with a few other options:
--recreate-lock-file|--no-update-lock-file|--no-write-lock-file|--no-registries|--commit-lock-file)
lockFlags+=("$i")
;;
--update-input)
j="$1"; shift 1
lockFlags+=("$i" "$j")
;;
--override-input)
I couldn't however find where to grab them from the local variables, although I do notice them in nix build --<tab>
.
It sometimes eats the whole line when pressing tab.
The second line is what I typed, and the third line is what happened after pressing tab. Note that it also eat my leading ▶
.
Press another tab, then the command is back but the leading notation is still eaten.
I'm using oh-my-zsh
with theme avit
.
Yup, another issue is that nix flake update --update-input
and similar commands won't receive proper completion.
I'll leave this as "good enough"-solution for now though until it's clear whether that's a suitable approach or the internal completion output of Nix is better (and Nix probably implements such a completion on its own).
Closing for now. This isn't compatible with current nixUnstable
and I don't see a trivial reason to fix this. As suggested previously, I'll try NIX_GET_COMPLETIONS
.
For those who are following this thread:
nix
from now on. Using NIX_GET_COMPLETIONS
my save a lot of time.nix build -f .
doesn't seem to complete packages properlynix build .#.<Tab>
)NIX_GET_COMPLETIONS=4 nix build -f .
should be used to provide stuff for the fourth argument, but throws an assertion error.
:warning: Caution: very early (and probably broken) draft to support Nix 2.4 completion (with and without
flakes
-support).Todo:
Note: I recommend to review this commit-by-commit, unfortunately the diff grew a bit too much.
PATH?
, see e.g.nix add-to-store --help
for instance)nix build .#packages
)nix flake
subcommandsnix flake cmd
cli optionsflake#attr
-expressions)nix shell nixpkgs#nixStabe
(currently onlynix shell nixpkgs#packages.x86_64-linux.nixStable
gets comleted).--experimental-features
/--log-format
prompt_nix_shell_setup
fornix develop/shell/run
Refs #32