summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-01-23 06:09:05 +0100
committerhut <hut@lavabit.com>2010-01-23 06:09:05 +0100
commit316ff5a92b1bc0fee1a1ddf946880f1697a35190 (patch)
tree395a7832785d81d53be5c785b6b532fa36f2837c /ranger
parentf601af14dff59355f678a51a2e257d1e376b74f5 (diff)
downloadranger-316ff5a92b1bc0fee1a1ddf946880f1697a35190.tar.gz
console: better tab completion for OpenConsole
Diffstat (limited to 'ranger')
-rw-r--r--ranger/gui/widgets/console.py17
1 files changed, 10 insertions, 7 deletions
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 = {}