diff options
author | fluxgen <fluxgen> | 2003-07-10 10:18:08 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2003-07-10 10:18:08 (GMT) |
commit | 481c0faeb50b86ad4fd7b946ca9e4a94932a382f (patch) | |
tree | 67578b8bbc0a13db6dec49b37da1b2bcff9ff334 /util/fbrun | |
parent | 51d5903898f72f0df2909d6bad426515c6361a5a (diff) | |
download | fluxbox_lack-481c0faeb50b86ad4fd7b946ca9e4a94932a382f.zip fluxbox_lack-481c0faeb50b86ad4fd7b946ca9e4a94932a382f.tar.bz2 |
patch that keeps the fbrun_history clean by not allowing
duplicates to get placed in the history. Thanks David J Burger
Diffstat (limited to 'util/fbrun')
-rw-r--r-- | util/fbrun/FbRun.cc | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/util/fbrun/FbRun.cc b/util/fbrun/FbRun.cc index 9c4d1d5..6c7a53a 100644 --- a/util/fbrun/FbRun.cc +++ b/util/fbrun/FbRun.cc | |||
@@ -19,7 +19,7 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | // $Id: FbRun.cc,v 1.13 2003/06/25 12:01:23 fluxgen Exp $ | 22 | // $Id: FbRun.cc,v 1.14 2003/07/10 10:18:08 fluxgen Exp $ |
23 | 23 | ||
24 | #include "FbRun.hh" | 24 | #include "FbRun.hh" |
25 | 25 | ||
@@ -86,12 +86,35 @@ void FbRun::run(const std::string &command) { | |||
86 | 86 | ||
87 | // save command history to file | 87 | // save command history to file |
88 | if (m_runtext.size() != 0) { // no need to save empty command | 88 | if (m_runtext.size() != 0) { // no need to save empty command |
89 | // open file in append mode | 89 | |
90 | ofstream outfile(m_history_file.c_str(), ios::app); | 90 | // don't allow duplicates into the history file, first |
91 | if (outfile) | 91 | // look for a duplicate |
92 | outfile<<m_runtext<<endl; | 92 | if (m_current_history_item < m_history.size() |
93 | else | 93 | && m_runtext == m_history[m_current_history_item]) { |
94 | cerr<<"FbRun Warning: Can't write command history to file: "<<m_history_file<<endl; | 94 | // m_current_history_item is the duplicate |
95 | } else { | ||
96 | int i; | ||
97 | for (i = 0; i < m_history.size(); i++) | ||
98 | if (m_runtext == m_history[i]) break; | ||
99 | m_current_history_item = i; | ||
100 | } | ||
101 | |||
102 | // now m_current_history_item points at the duplicate, or | ||
103 | // at m_history.size() if no duplicate | ||
104 | fstream inoutfile(m_history_file.c_str(), ios::in|ios::out); | ||
105 | if (inoutfile) { | ||
106 | int i = 0; | ||
107 | // read past history items before current | ||
108 | for (string line; !inoutfile.eof() && i < m_current_history_item; i++) | ||
109 | getline(inoutfile, line); | ||
110 | // write the history items that come after current | ||
111 | for (i++; i < m_history.size(); i++) | ||
112 | inoutfile<<m_history[i]<<endl; | ||
113 | // and append the current one back to the end | ||
114 | inoutfile<<m_runtext<<endl; | ||
115 | inoutfile.close(); | ||
116 | } else | ||
117 | cerr<<"FbRun Warning: Can't write command history to file: "<<m_history_file<<endl; | ||
95 | } | 118 | } |
96 | FbTk::App::instance()->end(); // end application | 119 | FbTk::App::instance()->end(); // end application |
97 | m_end = true; // mark end of processing | 120 | m_end = true; // mark end of processing |