diff options
-rw-r--r-- | ranger/commands.py | 75 | ||||
-rw-r--r-- | ranger/container/environment.py | 5 | ||||
-rw-r--r-- | ranger/gui/widgets/console.py | 17 |
3 files changed, 48 insertions, 49 deletions
diff --git a/ranger/commands.py b/ranger/commands.py index d016a822..e61e9fd8 100644 --- a/ranger/commands.py +++ b/ranger/commands.py @@ -47,51 +47,43 @@ class cd(Command): self.fm.enter_dir(destination) def tab(self): + from os.path import dirname, basename, expanduser, join, isdir + line = parse(self.line) + pwd = self.fm.env.pwd.path + try: - dest = line.chunks[1] + rel_dest = line.chunks[1] except IndexError: - dest = '' - - if dest.startswith('~'): - return line + os.path.expanduser(dest) + '/' - - absolute = lambda path: os.path.join(self.fm.env.pwd.path, path) - absdest = absolute(dest) - -# if dest == '': -# return sorted(os.listdir(dest)) + rel_dest = '' - if dest.endswith('/') or dest == '': - if os.path.isdir(dest): - walker = os.walk(absdest) - _, dirnames, _ = walker.next() - dirnames.sort() - return (line.line + dirname for dirname in dirnames) + if rel_dest.startswith('~'): + return line + expanduser(rel_dest) + '/' + abs_dest = join(pwd, rel_dest) + abs_dirname = dirname(abs_dest) + rel_basename = basename(rel_dest) + rel_dirname = dirname(rel_dest) + try: - original_dirname = os.path.dirname(absdest) - basename = os.path.basename(absdest) - - walker = os.walk(original_dirname) - _, dirnames, _ = walker.next() - dirnames = [dn for dn in dirnames if dn.startswith(basename)] - + if rel_dest.endswith('/') or rel_dest == '': + _, dirnames, _ = os.walk(abs_dest).next() + else: + _, dirnames, _ = os.walk(abs_dirname).next() + dirnames = [dn for dn in dirnames \ + if dn.startswith(rel_basename)] + except (OSError, StopIteration): + pass + else: dirnames.sort() - start = line + os.path.dirname(dest) + '/' if len(dirnames) == 0: return - elif len(dirnames) == 1: - if os.path.isdir(os.path.join(absdest, dirnames[0])): - return start + dirnames[0] + '/' - else: - return start + dirnames[0] - else: - return (start + dirname for dirname in dirnames) - except OSError: - pass + if len(dirnames) == 1: + return line + join(rel_dirname, dirnames[0]) + '/' + + return (line + join(rel_dirname, dirname) for dirname in dirnames) # -------------------------------- rest @@ -104,7 +96,18 @@ for varname, var in vars().copy().items(): pass def execute(name, line): - return by_name[name](line).execute() + try: + command = by_name[name](line) + except KeyError: + pass + else: + command.execute() def tab(name, line): - return by_name[name](line).tab() + try: + command = by_name[name](line) + except KeyError: + pass + else: + return command.tab() + diff --git a/ranger/container/environment.py b/ranger/container/environment.py index a6d291cf..11c0082b 100644 --- a/ranger/container/environment.py +++ b/ranger/container/environment.py @@ -1,4 +1,4 @@ -from os.path import abspath, normpath, join, expanduser +from os.path import abspath, normpath, join, expanduser, isdir from ranger.fsobject.directory import Directory, NoDirectoryGiven from ranger.container import KeyBuffer, History from ranger.shared import SettingsAware @@ -91,6 +91,9 @@ level <0 => parent directories""" # get the absolute path path = normpath(join(self.path, expanduser(path))) + if not isdir(path): + return + try: new_pwd = self.get_directory(path) except NoDirectoryGiven: diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py index 25341e00..7421db98 100644 --- a/ranger/gui/widgets/console.py +++ b/ranger/gui/widgets/console.py @@ -140,7 +140,7 @@ class CommandConsole(Console): prompt = ':' def execute(self): - self._exec_cmd() + commands.execute(self._get_cmd(), self.line) Console.execute(self) def tab(self, n=1): @@ -163,26 +163,19 @@ class CommandConsole(Console): self.line = self.tab_deque[0] self.pos = len(self.line) - def _get_tab(self): - cmd = self._get_cmd() - try: - return commands.tab(cmd, self.line) - except KeyError: - return None - def _get_cmd(self): try: return self.line.split()[0] except: return '' - def _exec_cmd(self): + def _get_tab(self): cmd = self._get_cmd() try: - commands.execute(cmd, self.line) + return commands.tab(cmd, self.line) except KeyError: - pass # command not found! - + return commands.tab(None, self.line) + class QuickCommandConsole(Console): prompt = '>' |