summary refs log tree commit diff stats
path: root/ranger/config/commands.py
diff options
context:
space:
mode:
authorhut <hut@lepus.uberspace.de>2014-12-05 00:25:28 +0100
committerhut <hut@lepus.uberspace.de>2014-12-05 00:25:57 +0100
commit1f58043102c54d3fdc1243931e2b02151610dd2b (patch)
tree170966c936fd0b1b1c3f7b676b3da231385bf6d7 /ranger/config/commands.py
parent42325092019837545a67b0851a3bbc7104f15f57 (diff)
downloadranger-1f58043102c54d3fdc1243931e2b02151610dd2b.tar.gz
config/commands.py: added :default_linemode command
Diffstat (limited to 'ranger/config/commands.py')
-rw-r--r--ranger/config/commands.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py
index 8485c784..db14403f 100644
--- a/ranger/config/commands.py
+++ b/ranger/config/commands.py
@@ -381,6 +381,43 @@ class setintag(setlocal):
         self.fm.set_option_from_string(name, value, tags=tags)
 
 
+class default_linemode(Command):
+    def execute(self):
+        import re
+        from ranger.container.fsobject import POSSIBLE_LINEMODES
+
+        if len(self.args) < 2:
+            self.fm.notify("Usage: default_linemode [path=<regexp> | tag=<tag(s)>] <linemode>", bad=True)
+
+        # Extract options like "path=..." or "tag=..." from the command line
+        arg1 = self.arg(1)
+        method = "always"
+        argument = None
+        if arg1.startswith("path="):
+            method = "path"
+            argument = re.compile(arg1[5:])
+            self.shift()
+        elif arg1.startswith("tag="):
+            method = "tag"
+            argument = arg1[4:]
+            self.shift()
+
+        # Extract and validate the line mode from the command line
+        linemode = self.rest(1)
+        if linemode not in POSSIBLE_LINEMODES:
+            self.fm.notify("Invalid linemode: %s; should be %s" %
+                    (linemode, "/".join(POSSIBLE_LINEMODES)), bad=True)
+
+        # Add the prepared entry to the fm.default_linemodes
+        entry = [method, argument, linemode]
+        self.fm.default_linemodes.appendleft(entry)
+
+        # Redraw the columns
+        if hasattr(self.fm.ui, "browser"):
+            for col in self.fm.ui.browser.columns:
+                col.need_redraw = True
+
+
 class quit(Command):
     """:quit