summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--TODO2
-rw-r--r--ranger/gui/widgets/console.py17
2 files changed, 11 insertions, 8 deletions
diff --git a/TODO b/TODO
index 8549caba..0c89142b 100644
--- a/TODO
+++ b/TODO
@@ -28,7 +28,7 @@ General
    (X) #34  10/01/09  display free disk space
    (X) #35  10/01/09  display disk usage of files in current directory
    ( ) #36  10/01/11  help coloring is terribly inefficient
-   ( ) #37  10/01/13  better tab completion for OpenConsole
+   (X) #37  10/01/13  better tab completion for OpenConsole
    ( ) #38  10/01/16  searching in pager
    (X) #39  10/01/17  flushinput not always good
    (X) #42  10/01/17  memorize directory for `` when using :cd
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py
index b3e49c47..b30b30b0 100644
--- a/ranger/gui/widgets/console.py
+++ b/ranger/gui/widgets/console.py
@@ -388,15 +388,18 @@ class OpenConsole(ConsoleWithTab):
 		self.close()
 
 	def _get_tab(self):
-		# for now, just add " %s"
-		if ' ' in self.line:
-			result = self.line
-			if result and result[-1] != ' ':
-				result += ' '
-			return result + '%s '
-		else:
+		try:
+			position_of_last_space = self.line.rindex(" ")
+		except ValueError:
 			return (program + ' ' for program in self.fm.executables \
 					if program.startswith(self.line))
+		if position_of_last_space == len(self.line) - 1:
+			return self.line + '%s '
+		else:
+			before_word, start_of_word = self.line.rsplit(' ', 1)
+			return (before_word + ' ' + file.basename \
+					for file in self.fm.env.pwd.files \
+					if file.basename.startswith(start_of_word))
 
 	def _substitute_metachars(self, command):
 		dct = {}