From 507782e5d4e21ca9df9bf774228e373d9c3aef8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCbking?= Date: Sun, 18 Sep 2016 15:18:04 +0200 Subject: escape special chars in filenames This follows the escaped chars in bash completion and allows to pass filenames with spaces etc. Using quotes would be another option but requires special handling of "~" and, what's worse, either hand-correcting the cursor position (into the quoted area) or more completion mumbo-jumbo to handle the quotes. --- util/fbrun/FbRun.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/util/fbrun/FbRun.cc b/util/fbrun/FbRun.cc index 19f6444..780d22a 100644 --- a/util/fbrun/FbRun.cc +++ b/util/fbrun/FbRun.cc @@ -482,6 +482,13 @@ void FbRun::tabCompleteApps() { std::string entry = dir.readFilename(); if (entry == "." || entry == "..") continue; + // escape special characters + std::string needle(" !\"$&'()*,:;<=>?@[\\]^`{|}"); + std::size_t pos = 0; + while ((pos = entry.find_first_of(needle, pos)) != std::string::npos) { + entry.insert(pos, "\\"); + pos += 2; + } if (FbTk::FileUtil::isDirectory(std::string(path + entry).c_str())) m_files.push_back(prefix + entry + "/"); else -- cgit v0.11.2