all repos — fluxbox @ 1910d5af463ebc9e49cb53a14377f557288c6139

custom fork of the fluxbox windowmanager

fix the no-writing-history issue for fbrun
mathias mathias
commit

1910d5af463ebc9e49cb53a14377f557288c6139

parent

d39897f19dbbb728971e1320621b3ef911ef4c85

1 files changed, 19 insertions(+), 12 deletions(-)

jump to
M util/fbrun/FbRun.ccutil/fbrun/FbRun.cc

@@ -140,20 +140,27 @@ break;

} } - // now m_current_history_item points at the duplicate, or - // at m_history.size() if no duplicate fstream inoutfile(m_history_file.c_str(), ios::in|ios::out); if (inoutfile) { - int i = 0; - // read past history items before current - for (string line; !inoutfile.eof() && i < m_current_history_item; i++) - getline(inoutfile, line); - // write the history items that come after current - for (i++; i < m_history.size(); i++) - inoutfile<<m_history[i]<<endl; - - // and append the current one back to the end - inoutfile<<text()<<endl; + // now m_current_history_item points at the duplicate, or + // at m_history.size() if no duplicate + if (m_current_history_item != m_history.size()) { + int i = 0; + // read past history items before current + for (; inoutfile.good() && i < m_current_history_item; i++) + inoutfile.ignore(1, '\n'); + + // write the history items that come after current + for (i++; i < m_history.size(); i++) + inoutfile<<m_history[i]<<endl; + + } else { + // set put-pointer at end of file + inoutfile.seekp(0, ios::end); + } + // append current command to the file + inoutfile<<command<<endl; + } else cerr<<"FbRun Warning: Can't write command history to file: "<<m_history_file<<endl; }