diff --git a/src/nix/repl.cc b/src/nix/repl.cc index 8edd8c69633c..b683db0f279f 100644 --- a/src/nix/repl.cc +++ b/src/nix/repl.cc @@ -131,6 +131,32 @@ static char * completionCallback(char * s, int *match) { auto *res = strdup(possible.begin()->c_str() + strlen(s)); if (!res) throw Error("allocation failure"); return res; + } else if (possible.size() > 1) { + size_t startLen = strlen(s); + size_t len = startLen; + while (true) { + bool same = true; + try { + char c = possible.begin()->at(len); + for (auto &p : possible) { + if (p.at(len) != c) { + same = false; + break; + } + } + } catch (std::out_of_range &) { + same = false; + } + if (!same) + break; + ++len; + } + if (len > startLen) { + *match = 1; + auto *res = strdup(std::string(*possible.begin(), startLen, len-startLen).c_str()); + if (!res) throw Error("allocation failure"); + return res; + } } *match = 0;