Utils/Console: Add short help to 'ls' output
[senf.git] / Utils / Console / LineEditor.cc
index 95f1153..31df1f7 100644 (file)
@@ -144,11 +144,8 @@ completePath(term::LineEditor & editor, unsigned b, unsigned e,
     ParseCommandInfo::TokensRange path (cmd.commandPath());
     if (path.empty()) {
         DirectoryNode::ChildrenRange cs (client().cwd().children());
-        for (DirectoryNode::ChildrenRange::iterator i (cs.begin()); i != cs.end(); ++i) {
-            completions.push_back(i->first);
-            if (i->second->isDirectory())
-                completions.push_back(i->first + "/");
-        }
+        for (DirectoryNode::ChildrenRange::iterator i (cs.begin()); i != cs.end(); ++i)
+            completions.push_back(i->first + (i->second->followLink().isDirectory() ? "/" : " "));
         return;
     }
     
@@ -169,20 +166,24 @@ completePath(term::LineEditor & editor, unsigned b, unsigned e,
             basePath += "../";
         }
         else if (*i == WordToken(".")) 
-            ;
+            basePath += "./";
         else {
             if (dir->hasChild(i->value())) {
-                dir = & dir->getDirectory(i->value());
+                try {
+                    dir = & dir->getDirectory(i->value());
+                }
+                catch (std::bad_cast &) {
+                    return;
+                }
                 basePath += i->value() + "/";
-            } else {
+            } 
+            else {
                 DirectoryNode::ChildrenRange cs (dir->completions(i->value()));
                 if (has_one_elt(cs)) {
-                    GenericNode * node (cs.begin()->second.get());
-                    if (node->isLink())
-                        node = & static_cast<LinkNode*>(node)->follow();
-                    if (!node->isDirectory())
+                    GenericNode & node (cs.begin()->second->followLink());
+                    if (!node.isDirectory())
                         return;
-                    dir = static_cast<DirectoryNode*>(node);
+                    dir = static_cast<DirectoryNode*>(&node);
                     basePath += cs.begin()->first + "/";
                 }
                 else
@@ -191,11 +192,9 @@ completePath(term::LineEditor & editor, unsigned b, unsigned e,
         }
 
     DirectoryNode::ChildrenRange cs (dir->completions(i->value()));
-    for (DirectoryNode::ChildrenRange::iterator j (cs.begin()); j != cs.end(); ++j) {
-        completions.push_back(basePath + j->first);
-        if (j->second->isDirectory())
-            completions.push_back(basePath + j->first + "/");
-    }
+    for (DirectoryNode::ChildrenRange::iterator j (cs.begin()); j != cs.end(); ++j)
+        completions.push_back(basePath + j->first 
+                              + (j->second->followLink().isDirectory() ? "/" : " "));
 }
 
 ///////////////////////////////cc.e////////////////////////////////////////