summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/conf/keys.py5
-rw-r--r--ranger/conf/options.py8
-rw-r--r--ranger/environment.py36
-rw-r--r--ranger/fm.py3
4 files changed, 50 insertions, 2 deletions
diff --git a/ranger/conf/keys.py b/ranger/conf/keys.py
index 5ad4e510..f1349717 100644
--- a/ranger/conf/keys.py
+++ b/ranger/conf/keys.py
@@ -22,8 +22,13 @@ def initialize_commands(cl):
 	def cd(path):
 		return lambda fm: fm.enter_dir(path)
 
+	def history(n):
+		return lambda fm: fm.history_go(n)
+
 	cl.bind(FM.move_left,           'h', curses.KEY_BACKSPACE, 127)
 	cl.bind(FM.move_right,          'l', curses.KEY_ENTER, ctrl('j'))
+	cl.bind(history(-1),            'H')
+	cl.bind(history(1),             'L')
 	cl.bind(move( relative = 1 ),   'j')
 	cl.bind(move_pages( 0.5 ),      'J')
 	cl.bind(move( relative = -1 ),  'k')
diff --git a/ranger/conf/options.py b/ranger/conf/options.py
index 11ed80cc..e8baa60d 100644
--- a/ranger/conf/options.py
+++ b/ranger/conf/options.py
@@ -4,4 +4,10 @@ def get():
 
 def dummy():
 	""" provide a way of getting options until get() is implemented """
-	return { 'show_hidden': False, 'scroll_offset': 2, 'directories_first': True, 'preview_files' : False }
+	return {
+			'show_hidden': False,
+			'scroll_offset': 2,
+			'directories_first': True,
+			'preview_files' : False,
+			'max_history_size': 20
+			}
diff --git a/ranger/environment.py b/ranger/environment.py
index a15abba2..e0ac646a 100644
--- a/ranger/environment.py
+++ b/ranger/environment.py
@@ -14,6 +14,8 @@ class Environment():
 		self.keybuffer = ()
 		self.copy = None
 		self.termsize = (24, 80)
+		self.history = []
+		self.history_position = -1
 
 	def key_append(self, key):
 		self.keybuffer += (key, )
@@ -53,8 +55,37 @@ class Environment():
 
 			path.move_pointer_to_file_path(last_path)
 			last_path = path
+	
+	def history_go(self, relative):
+		if not self.history:
+			return
+
+		if self.history_position == -1:
+			if relative > 0:
+				return
+			elif relative < 0:
+				self.history_position = max( 0, len(self.history) - 1 + relative )
+		else:
+			self.history_position += relative
+			if self.history_position < 0:
+				self.history_position = 0
+
+		if self.history_position >= len(self.history) - 1:
+			self.history_position = -1
 
-	def enter_dir(self, path):
+		self.enter_dir(self.history[self.history_position], history=False)
+
+	def history_add(self, path):
+		if self.opt['max_history_size']:
+			if len(self.history) > self.history_position > (-1):
+				self.history = self.history[0 : self.history_position + 1]
+			if not self.history or (self.history and self.history[-1] != path):
+				self.history_position = -1
+				self.history.append(path)
+			if len(self.history) > self.opt['max_history_size']:
+				self.history.pop(0)
+
+	def enter_dir(self, path, history = True):
 		# get the absolute path
 		path = normpath(join(self.path, expanduser(path)))
 
@@ -87,5 +118,8 @@ class Environment():
 		self.pwd.sort_if_outdated()
 		self.cf = self.pwd.pointed_file
 
+		if history:
+			self.history_add(path)
+
 		return True
 
diff --git a/ranger/fm.py b/ranger/fm.py
index 55fd64f3..d314fea4 100644
--- a/ranger/fm.py
+++ b/ranger/fm.py
@@ -41,6 +41,9 @@ class FM():
 				self.execute_file(path)
 		except AttributeError:
 			pass
+
+	def history_go(self, relative):
+		self.env.history_go(relative)
 	
 	def handle_mouse(self):
 		self.ui.handle_mouse(self)