From 4ead0882adafbcc419f3a0c8e40f58846dda0dbd Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 18 Mar 2012 23:44:47 +0100 Subject: ext.rifle: polishing --- ranger/core/actions.py | 14 +++--- ranger/defaults/commands.py | 2 +- ranger/defaults/rifle.conf | 46 ++++++++++++-------- ranger/ext/rifle.py | 103 +++++++++++++++++++++++++++++++++----------- 4 files changed, 113 insertions(+), 52 deletions(-) diff --git a/ranger/core/actions.py b/ranger/core/actions.py index d5d38de9..f701c08f 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -17,6 +17,7 @@ from ranger.ext.relative_symlink import relative_symlink from ranger.ext.keybinding_parser import key_to_string, construct_keybinding from ranger.ext.shell_escape import shell_quote from ranger.ext.next_available_filename import next_available_filename +from ranger.ext.rifle import squash_flags from ranger.core.shared import FileManagerAware, EnvironmentAware, \ SettingsAware from ranger.fsobject import File @@ -292,19 +293,16 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware): elif type(files) not in (list, tuple): files = [files] - if 'flags' in kw: - from ranger.core.runner import Context - context = Context(files=list(files), flags=kw['flags']) - context.squash_flags() - if 'c' in context.flags: - files = [self.fm.env.cf] + flags = squash_flags(kw.get('flags', '')) + if 'c' in flags: + files = [self.fm.env.cf] self.signal_emit('execute.before', keywords=kw) filenames = [f.path for f in files] mimetype = files[0].mimetype if files else None - label = kw['label'] if 'label' in kw else None + label = kw.get('app', None) try: - return self.rifle.execute(filenames, mode, label, mimetype) + return self.rifle.execute(filenames, mode, label, flags, mimetype) finally: self.signal_emit('execute.after') diff --git a/ranger/defaults/commands.py b/ranger/defaults/commands.py index 054bb020..52a1d30e 100644 --- a/ranger/defaults/commands.py +++ b/ranger/defaults/commands.py @@ -312,7 +312,7 @@ class open_with(Command): return app, flags, int(mode) def _is_app(self, arg): - return (not self._is_flags(arg) and arg in get_executables()) + return not self._is_flags(arg) and not arg.isdigit() def _is_flags(self, arg): return all(x in ALLOWED_FLAGS for x in arg) diff --git a/ranger/defaults/rifle.conf b/ranger/defaults/rifle.conf index 5851f447..2e86d463 100644 --- a/ranger/defaults/rifle.conf +++ b/ranger/defaults/rifle.conf @@ -7,12 +7,11 @@ # Syntax: # , , ... = command # -# Prefixing a condition with a "!" will negate its result. -# # The command can contain these environment variables: # $1-$9 | The n-th selected file # $@ | All selected files # +# Prefixing a condition with "!" will negate its result. # These conditions are currently supported: # ext | The regexp matches the extension of $1 # mime | The regexp matches the mime type of $1 @@ -24,28 +23,39 @@ # # There are also pseudo-conditions which have a "side effect": # flag | Change how the program is run. See below. -# label