aboutsummaryrefslogtreecommitdiff
path: root/src/nix/main.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-05-10 20:32:21 +0200
committerEelco Dolstra <edolstra@gmail.com>2020-05-10 20:32:21 +0200
commit91ddee6bf045b1c6144d14233abdb96127186ec3 (patch)
tree5c75576b453c177c3a43a422db1323cb7452b7f8 /src/nix/main.cc
parent14a3a62bfca6c572b9a415cfa80cdbd7ad4326b3 (diff)
nix: Implement basic bash completion
Diffstat (limited to 'src/nix/main.cc')
-rw-r--r--src/nix/main.cc16
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");