summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorAbdó Roig-Maranges <abdo.roig@gmail.com>2012-12-06 14:19:45 +0100
committerhut <hut@lavabit.com>2012-12-09 15:16:47 +0100
commita279353c64008a60092fe13638ef67a3da1fc1ef (patch)
tree9bd42269d4f5483f44820e46b28d90579a9184a3 /ranger
parent864331a0edd73b364c22985bbb1aa7f55dcf25f4 (diff)
downloadranger-a279353c64008a60092fe13638ef67a3da1fc1ef.tar.gz
added setlocal command to handle local settings
Diffstat (limited to 'ranger')
-rw-r--r--ranger/api/commands.py2
-rw-r--r--ranger/config/commands.py31
-rw-r--r--ranger/config/rc.conf9
3 files changed, 39 insertions, 3 deletions
diff --git a/ranger/api/commands.py b/ranger/api/commands.py
index aaadde5d..15816247 100644
--- a/ranger/api/commands.py
+++ b/ranger/api/commands.py
@@ -146,6 +146,8 @@ class Command(FileManagerAware):
 
 	def shift(self):
 		del self.args[0]
+		del self.argspos[0]
+		self._setting_line = None
 		self._shifted += 1
 
 	def tabinsert(self, word):
diff --git a/ranger/config/commands.py b/ranger/config/commands.py
index 489f2426..3a3b84c4 100644
--- a/ranger/config/commands.py
+++ b/ranger/config/commands.py
@@ -76,6 +76,8 @@
 # of ranger.
 # ===================================================================
 
+import os
+
 from ranger.api.commands import *
 from ranger.ext.get_executables import get_executables
 from ranger.core.runner import ALLOWED_FLAGS
@@ -89,7 +91,7 @@ class alias(Command):
 
 	context = 'browser'
 	resolve_macros = False
-	
+
 	def execute(self):
 		if not self.arg(1) or not self.arg(2):
 			self.fm.notify('Syntax: alias <newcommand> <oldcommand>', bad=True)
@@ -406,6 +408,29 @@ class set_(Command):
 				return self.firstpart + 'False'
 
 
+class setlocal(set_):
+	"""
+	:setlocal path=<python string> <option name>=<python expression>
+
+	Gives an option a new value.
+	"""
+	PATH_RE=re.compile(r'^\s*path="?(.*?)"?\s*$')
+	def execute(self):
+		match = self.PATH_RE.match(self.arg(1))
+		if match:
+			path = os.path.normpath(os.path.expanduser(match.group(1)))
+			self.shift()
+		elif self.fm.thisdir:
+			path = self.fm.thisdir.path
+		else:
+			path = None
+
+		if path:
+			name = self.arg(1)
+			name, value, _ = self.parse_setting_line()
+			self.fm.set_option_from_string(name, value, localpath=path)
+
+
 class quit(Command):
 	"""
 	:quit
@@ -514,7 +539,7 @@ class mark(Command):
 		input = self.rest(1)
 		searchflags = re.UNICODE
 		if input.lower() == input: # "smartcase"
-			searchflags |= re.IGNORECASE 
+			searchflags |= re.IGNORECASE
 		pattern = re.compile(input, searchflags)
 		for fileobj in cwd.files:
 			if pattern.search(fileobj.basename):
@@ -851,7 +876,7 @@ class relink(Command):
 class help_(Command):
 	"""
 	:help
-	
+
 	Display ranger's manual page.
 	"""
 	name = 'help'
diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf
index 88e242fd..b2ffa725 100644
--- a/ranger/config/rc.conf
+++ b/ranger/config/rc.conf
@@ -134,6 +134,14 @@ set sort_directories_first true
 # (Especially on xterm)
 set xterm_alt_key true
 
+# ===================================================================
+# == Local Options
+# ===================================================================
+# You can set local options that only affect a single directory.
+
+# Examples:
+# setlocal path=~/downloads sort mtime
+# setlocal path="~/dir with spaces" use_preview_script false
 
 # ===================================================================
 # == Command Aliases in the Console
@@ -143,6 +151,7 @@ alias e    edit
 alias q    quit
 alias q!   quitall
 alias qall quitall
+alias setl setlocal
 
 # ===================================================================
 # == Define keys for the browser