Scheduler/Console: Make '..' work in Console (closes: #14754)
[senf.git] / Scheduler / Console / Executor.cc
index 5a6337d..d6218d8 100644 (file)
@@ -33,6 +33,7 @@
 #include "../../Utils/senfassert.hh"
 #include "../../Utils/Range.hh"
 #include "../../Utils/String.hh"
+#include "../../Utils/range.hh"
 
 //#include "Executor.mpp"
 #define prefix_
@@ -248,8 +249,17 @@ senf::console::Executor::traverseNode(ParseCommandInfo::TokensRange const & path
                               path.begin(),
                               boost::prior(path.end())),
                           dir);
+        // For auto-cd support we need to check against '.' and '..' here too
+        Token const & tok (*boost::prior(path.end()));
+        if (tok == WordToken("..")) {
+            if (dir.size() > 1)
+                dir.pop_back();
+            return *dir.back().lock();
+        }
         DirectoryNode & base (*dir.back().lock());
-        std::string const & name (complete(base, boost::prior(path.end())->value()));
+        if (tok == WordToken("."))
+            return base;
+        std::string const & name (complete(base, tok.value()));
         if (policy_)
             policy_( base, name );
         return dir.back().lock()->get(name);
@@ -301,7 +311,7 @@ prefix_ std::string senf::console::Executor::complete(DirectoryNode & dir,
 {
     if (! dir.hasChild(name)) {
         DirectoryNode::ChildrenRange completions (dir.completions(name));
-        if (completions.size() == 1)
+        if (has_one_elt(completions))
             return completions.begin()->first;
     }
     return name;