limit fbrun history size

the default is 1024-1025, values are read from the FBRUN_HISTORY_SIZE
environment variable
NOTICE: the limit isn't hard, but will typically be n+1 and only n if
the new entry is already present in the last n entries

REQUEST: 202
This commit is contained in:
Thomas Lübking 2016-07-23 14:19:10 +02:00
parent e85dc01d28
commit 0ca5daf997

View file

@ -166,13 +166,22 @@ void FbRun::run(const std::string &command) {
return; return;
} }
for (unsigned i = 0; i != m_history.size(); ++i) { int n = 1024;
char *a = getenv("FBRUN_HISTORY_SIZE");
if (a)
n = atoi(a);
int j = m_history.size();
--n; // NOTICE: this should be "-=2", but a duplicate entry in the late
// (good) section would wait "too" long
// (we'd wait until 3 items are left and then still skip one for being a dupe)
// IOW: the limit is either n or n+1, depending in the history structure
for (unsigned int i = 0; i != m_history.size(); ++i) {
// don't allow duplicates into the history file // don't allow duplicates into the history file
if (m_history[i] == command) if (--j > n || m_history[i] == command)
continue; continue;
outfile<<m_history[i]<<endl; outfile<<m_history[i]<<endl;
} }
if (++n > 0) // n was decremented for the loop
outfile << command << endl; outfile << command << endl;
outfile.close(); outfile.close();
} }