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
Thomas Lübking thomas.luebking@gmail.com
1 files changed,
13 insertions(+),
4 deletions(-)
jump to
M
util/fbrun/FbRun.cc
→
util/fbrun/FbRun.cc
@@ -166,14 +166,23 @@ cerr<<"FbRun Warning: Can't write command history to file: "<<m_history_file<<endl;
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 - if (m_history[i] == command) + if (--j > n || m_history[i] == command) continue; - outfile<<m_history[i]<<endl; } - outfile<<command<<endl; + if (++n > 0) // n was decremented for the loop + outfile << command << endl; outfile.close(); }