@@ -69,6 +69,7 @@ struct NixRepl
69
69
70
70
const static int envSize = 32768 ;
71
71
std::shared_ptr<StaticEnv> staticEnv;
72
+ Value lastLoaded;
72
73
Env * env;
73
74
int displ;
74
75
StringSet varNames;
@@ -95,6 +96,7 @@ struct NixRepl
95
96
void loadFiles ();
96
97
void loadFlakes ();
97
98
void reloadFilesAndFlakes ();
99
+ void showLastLoaded ();
98
100
void addAttrsToScope (Value & attrs);
99
101
void addVarToScope (const Symbol name, Value & v);
100
102
Expr * parseString (std::string s);
@@ -372,6 +374,7 @@ ProcessLineResult NixRepl::processLine(std::string line)
372
374
<< " current profile\n "
373
375
<< " :l, :load <path> Load Nix expression and add it to scope\n "
374
376
<< " :lf, :load-flake <ref> Load Nix flake and add it to scope\n "
377
+ << " :ll, :last-loaded Show most recently loaded variables added to scope\n "
375
378
<< " :p, :print <expr> Evaluate and print expression recursively\n "
376
379
<< " Strings are printed directly, without escaping.\n "
377
380
<< " :q, :quit Exit nix-repl\n "
@@ -462,6 +465,10 @@ ProcessLineResult NixRepl::processLine(std::string line)
462
465
loadFlake (arg);
463
466
}
464
467
468
+ else if (command == " :ll" || command == " :last-loaded" ) {
469
+ showLastLoaded ();
470
+ }
471
+
465
472
else if (command == " :r" || command == " :reload" ) {
466
473
state->resetFileCache ();
467
474
reloadFilesAndFlakes ();
@@ -754,6 +761,16 @@ void NixRepl::initEnv()
754
761
varNames.emplace (state->symbols [i.first ]);
755
762
}
756
763
764
+ void NixRepl::showLastLoaded ()
765
+ {
766
+ RunPager pager;
767
+
768
+ for (auto & i : *lastLoaded.attrs ()) {
769
+ std::string_view name = state->symbols [i.name ];
770
+ logger->cout (name);
771
+ }
772
+ }
773
+
757
774
758
775
void NixRepl::reloadFilesAndFlakes ()
759
776
{
@@ -807,6 +824,27 @@ void NixRepl::addAttrsToScope(Value & attrs)
807
824
staticEnv->sort ();
808
825
staticEnv->deduplicate ();
809
826
notice (" Added %1% variables." , attrs.attrs ()->size ());
827
+
828
+ lastLoaded = attrs;
829
+
830
+ const int max_print = 20 ;
831
+ int counter = 0 ;
832
+ std::ostringstream loaded;
833
+ for (auto & i : attrs.attrs ()->lexicographicOrder (state->symbols )) {
834
+ if (counter >= max_print)
835
+ break ;
836
+
837
+ if (counter > 0 )
838
+ loaded << " , " ;
839
+
840
+ printIdentifier (loaded, state->symbols [i->name ]);
841
+ counter += 1 ;
842
+ }
843
+
844
+ notice (" %1%" , loaded.str ());
845
+
846
+ if (attrs.attrs ()->size () > max_print)
847
+ notice (" ... and %1% more; view with :ll" , attrs.attrs ()->size () - max_print);
810
848
}
811
849
812
850
0 commit comments