aboutsummaryrefslogtreecommitdiff
path: root/util/fbrun
diff options
context:
space:
mode:
authorThomas Lübking <thomas.luebking@gmail.com>2016-07-23 12:19:10 (GMT)
committerThomas Lübking <thomas.luebking@gmail.com>2016-07-23 14:58:04 (GMT)
commit0ca5daf997d08b415c7ea9149489ccf3366e3a74 (patch)
tree94d891b314e197fde5e7ec82046d7d04693e8fd3 /util/fbrun
parente85dc01d287fa0a070b59a494419dd416d1c54f1 (diff)
downloadfluxbox-0ca5daf997d08b415c7ea9149489ccf3366e3a74.zip
fluxbox-0ca5daf997d08b415c7ea9149489ccf3366e3a74.tar.bz2
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
Diffstat (limited to 'util/fbrun')
-rw-r--r--util/fbrun/FbRun.cc17
1 files changed, 13 insertions, 4 deletions
diff --git a/util/fbrun/FbRun.cc b/util/fbrun/FbRun.cc
index fdc8b38..321959e 100644
--- a/util/fbrun/FbRun.cc
+++ b/util/fbrun/FbRun.cc
@@ -166,14 +166,23 @@ void FbRun::run(const std::string &command) {
166 return; 166 return;
167 } 167 }
168 168
169 for (unsigned i = 0; i != m_history.size(); ++i) { 169 int n = 1024;
170 char *a = getenv("FBRUN_HISTORY_SIZE");
171 if (a)
172 n = atoi(a);
173 int j = m_history.size();
174 --n; // NOTICE: this should be "-=2", but a duplicate entry in the late
175 // (good) section would wait "too" long
176 // (we'd wait until 3 items are left and then still skip one for being a dupe)
177 // IOW: the limit is either n or n+1, depending in the history structure
178 for (unsigned int i = 0; i != m_history.size(); ++i) {
170 // don't allow duplicates into the history file 179 // don't allow duplicates into the history file
171 if (m_history[i] == command) 180 if (--j > n || m_history[i] == command)
172 continue; 181 continue;
173
174 outfile<<m_history[i]<<endl; 182 outfile<<m_history[i]<<endl;
175 } 183 }
176 outfile<<command<<endl; 184 if (++n > 0) // n was decremented for the loop
185 outfile << command << endl;
177 outfile.close(); 186 outfile.close();
178} 187}
179 188