diff options
author | hut <hut@lepus.uberspace.de> | 2014-12-05 00:25:28 +0100 |
---|---|---|
committer | hut <hut@lepus.uberspace.de> | 2014-12-05 00:25:57 +0100 |
commit | 1f58043102c54d3fdc1243931e2b02151610dd2b (patch) | |
tree | 170966c936fd0b1b1c3f7b676b3da231385bf6d7 /ranger | |
parent | 42325092019837545a67b0851a3bbc7104f15f57 (diff) | |
download | ranger-1f58043102c54d3fdc1243931e2b02151610dd2b.tar.gz |
config/commands.py: added :default_linemode command
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/config/commands.py | 37 | ||||
-rw-r--r-- | ranger/container/fsobject.py | 21 | ||||
-rw-r--r-- | ranger/core/fm.py | 1 |
3 files changed, 57 insertions, 2 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 diff --git a/ranger/container/fsobject.py b/ranger/container/fsobject.py index e5e0983e..59e23f6b 100644 --- a/ranger/container/fsobject.py +++ b/ranger/container/fsobject.py @@ -12,6 +12,9 @@ DOCUMENT_BASENAMES = ('bugs', 'bugs', 'changelog', 'copying', 'credits', BAD_INFO = '?' +POSSIBLE_LINEMODES = ("filename", "papertitle", "permissions") +DEFAULT_LINEMODE = "filename" + import re from grp import getgrgid from os import lstat, stat, getcwd @@ -82,8 +85,7 @@ class FileSystemObject(FileManagerAware, SettingsAware): basename_is_rel = False - # the line mode may be "filename", "permissions" or "papertitle" - _linemode = "filename" + _linemode = DEFAULT_LINEMODE def __init__(self, path, preload=None, path_is_abs=False, basename_is_rel=False): if not path_is_abs: @@ -106,6 +108,21 @@ class FileSystemObject(FileManagerAware, SettingsAware): except ValueError: self.extension = None + # Set the line mode from fm.default_linemodes + for method, argument, linemode in self.fm.default_linemodes: + if linemode in POSSIBLE_LINEMODES: + if method == "always": + self._linemode = linemode + break + if method == "path" and argument.search(path): + self._linemode = linemode + break + if method == "tag" and self.realpath in self.fm.tags and \ + self.fm.tags.marker(self.realpath) in argument: + self._linemode = linemode + break + + def __repr__(self): return "<{0} {1}>".format(self.__class__.__name__, self.path) diff --git a/ranger/core/fm.py b/ranger/core/fm.py index fbdc5a6a..3497f20c 100644 --- a/ranger/core/fm.py +++ b/ranger/core/fm.py @@ -57,6 +57,7 @@ class FM(Actions, SignalDispatcher): self.restorable_tabs = deque([], ranger.MAX_RESTORABLE_TABS) self.py3 = sys.version_info >= (3, ) self.previews = {} + self.default_linemodes = deque() self.loader = Loader() self.copy_buffer = set() self.do_cut = False |