Repository: xonsh/xonsh

Issue:
Regression in current folder tab completion (./executable)
In latest master when I type `./some_exe`, I have this turned into `some_executable`. Expected behavior: `./some_executable`

In version 0.1.6 this works well.

Add support for CDPATH
CDPATH works like PATH for `cd`, no CDPATH is like CDPATH=. but more prefixes can be added.



Discussion:
This is pretty annoying - It will get fixed soon.

Hi @naufraghi - This is cool idea and I'd like to see it merged in.  I have put in some in-line comments.  

I'd like to see some tests added for this too. It looks like you might need to start a new `test_dirstack.py` file in the tests dir.  Would you mind doing this?

Yes, I was searching for a good place for the tests. I'll have a look at
the other comments.

Il giorno 20:55 dom 10/mag/2015 Anthony Scopatz notifications@github.com
ha scritto:

> Hi @naufraghi https://github.com/naufraghi - This is cool idea and I'd
> like to see it merged in. I have put in some in-line comments.
> 
> I'd like to see some tests added for this too. It looks like you might
> need to start a new test_dirstack.py file in the tests dir. Would you
> mind doing this?
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/scopatz/xonsh/pull/225#issuecomment-100680576.

Hi @scopatz, I have updated the pull request.
Regarding [_add_cdpath](https://github.com/scopatz/xonsh/pull/225#discussion-diff-30004757), I think the empty list is the correct behaviour, because, breaking compatibility with bash, we always prefer an existing relative path.

Thanks @naufraghi - just a little bit of clean up is needed.

Done perhaps @scopatz 

Hi @naufraghi, this looks great! One last thing, though. Could you please add some docs to the tutorial, probably in the table in this section (https://github.com/scopatz/xonsh/blob/master/docs/tutorial.rst#environment-variables) about this new environment variable? Then this should be good to go.

Sorry for the lag, added some docs

Thanks @naufraghi!


Resolving patch:
diff --git a/xonsh/completer.py b/xonsh/completer.py
--- a/xonsh/completer.py
+++ b/xonsh/completer.py
@@ -104,7 +104,7 @@ def complete(self, prefix, line, begidx, endidx, ctx=None):
                 return sorted(self.module_complete(prefix))
             if cmd in self._all_commands():
                 # subproc mode; do path completions
-                return sorted(self.path_complete(prefix))
+                return sorted(self.path_complete(prefix, cdpath=True))
             else:
                 # if we're here, could be anything
                 rtn = set()
@@ -139,7 +139,8 @@ def _add_cdpaths(self, paths, prefix):
         env = builtins.__xonsh_env__
         for cdp in env.get("CDPATH", []):
             for s in iglobpath(os.path.join(cdp, prefix) + '*'):
-                paths.add(s)
+                if os.path.isdir(s):
+                    paths.add(os.path.basename(s))
 
     def cmd_complete(self, cmd):
         """Completes a command name based on what is on the $PATH"""
@@ -151,7 +152,7 @@ def module_complete(self, prefix):
         modules = set(sys.modules.keys())
         return {s for s in modules if s.startswith(prefix)}
 
-    def path_complete(self, prefix):
+    def path_complete(self, prefix, cdpath=False):
         """Completes based on a path name."""
         space = ' '  # intern some strings for faster appending
         slash = '/'
@@ -170,7 +171,8 @@ def path_complete(self, prefix):
             paths = {s.replace(home, tilde) for s in paths}
         self._add_env(paths, prefix)
         self._add_dots(paths, prefix)
-        self._add_cdpaths(paths, prefix)
+        if cdpath:
+            self._add_cdpaths(paths, prefix)
         return {os.path.normpath(s) for s in paths}
 
     def bash_complete(self, prefix, line, begidx, endidx):


Test patch: