diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-05-10 20:32:21 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-05-10 20:32:21 +0200 |
commit | 91ddee6bf045b1c6144d14233abdb96127186ec3 (patch) | |
tree | 5c75576b453c177c3a43a422db1323cb7452b7f8 /src/nix/main.cc | |
parent | 14a3a62bfca6c572b9a415cfa80cdbd7ad4326b3 (diff) |
nix: Implement basic bash completion
Diffstat (limited to 'src/nix/main.cc')
-rw-r--r-- | src/nix/main.cc | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/nix/main.cc b/src/nix/main.cc index 3915a4896..c491bc264 100644 --- a/src/nix/main.cc +++ b/src/nix/main.cc @@ -166,7 +166,21 @@ void mainWrapped(int argc, char * * argv) NixArgs args; - args.parseCmdline(argvToStrings(argc, argv)); + Finally printCompletions([&]() + { + if (completions) { + for (auto & s : *completions) + std::cout << s << "\n"; + } + }); + + try { + args.parseCmdline(argvToStrings(argc, argv)); + } catch (UsageError &) { + if (!completions) throw; + } + + if (completions) return; settings.requireExperimentalFeature("nix-command"); |