diff --git a/filecomplete.cpp b/filecomplete.cpp index b04758f..140d546 100644 --- a/filecomplete.cpp +++ b/filecomplete.cpp @@ -661,8 +661,9 @@ char* fc_readline() append_his(main_buf); if (need_turn) { std::string rep(main_buf); - if (rep.find("~") == 0) { - rep = get_home() + rep.substr(1, rep.size() - 1); + auto spos = rep.find("~"); + if (spos != std::string::npos) { + rep = rep.substr(0, spos) + get_home() + rep.substr(spos + 1, rep.size() - spos); std::memset(main_buf, 0x0, buf_size); std::snprintf(main_buf, buf_size, "%s", rep.c_str()); }