From 582c9ff2c211a5dcf7ff9f042dbec791541d34b6 Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 27 Dec 2009 00:54:20 +0100 Subject: generalized tab completion code of cd command --- ranger/commands.py | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/ranger/commands.py b/ranger/commands.py index 68b9c574..2c0593a3 100644 --- a/ranger/commands.py +++ b/ranger/commands.py @@ -19,29 +19,7 @@ class Command(FileManagerAware): def quick_open(self): """Override this""" -# -------------------------------- definitions - -class cd(Command): - """ - The cd command changes the directory. The command 'cd -' is - equivalent to typing ``. In the quick console, the directory - will be entered without the need to press enter, as soon as there - is one unambiguous match. - """ - - def execute(self): - line = parse(self.line) - try: - destination = line.rest(1) - except IndexError: - destination = '~' - - if destination == '-': - self.fm.enter_bookmark('`') - else: - self.fm.enter_dir(destination) - - def tab(self): + def _tab_through_directories(self): from os.path import dirname, basename, expanduser, join, isdir line = parse(self.line) @@ -79,6 +57,31 @@ class cd(Command): return line + join(rel_dirname, dirnames[0]) + '/' return (line + join(rel_dirname, dirname) for dirname in dirnames) + +# -------------------------------- definitions + +class cd(Command): + """ + The cd command changes the directory. The command 'cd -' is + equivalent to typing ``. In the quick console, the directory + will be entered without the need to press enter, as soon as there + is one unambiguous match. + """ + + def execute(self): + line = parse(self.line) + try: + destination = line.rest(1) + except IndexError: + destination = '~' + + if destination == '-': + self.fm.enter_bookmark('`') + else: + self.fm.enter_dir(destination) + + def tab(self): + return self._tab_through_directories() def quick_open(self): from os.path import isdir, join, normpath -- cgit 1.4.1-2-gfad0