summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2012-08-06 23:26:47 +0200
committerhut <hut@lavabit.com>2012-08-06 23:26:47 +0200
commitdfcfd112b1ebfba11a176c39366dc72ad887fd70 (patch)
treed6e4af67732e90bd8374b34d9042e0638c3d040c /ranger
parent796074b541aaca459c594fe517c11d275778eef6 (diff)
downloadranger-dfcfd112b1ebfba11a176c39366dc72ad887fd70.tar.gz
ext.rifle: implemented asking on unknown filetype (in ranger only)
this was requested here: https://github.com/hut/ranger/issues/36

adam8157:
  Why non-text files' default opener is editor now? It invoked open_with
  before.

  I think the old way is better. We can't describe all types in
  rifle.conf, so many types are defined as unknown non-text types, it's
  not appropriate to open them all with editor.
Diffstat (limited to 'ranger')
-rw-r--r--ranger/config/rifle.conf3
-rw-r--r--ranger/core/actions.py5
-rwxr-xr-xranger/ext/rifle.py3
3 files changed, 9 insertions, 2 deletions
diff --git a/ranger/config/rifle.conf b/ranger/config/rifle.conf
index ad4ba148..daed8b90 100644
--- a/ranger/config/rifle.conf
+++ b/ranger/config/rifle.conf
@@ -11,6 +11,8 @@
 #   $1-$9 | The n-th selected file
 #   $@    | All selected files
 #
+# If you use the special command "ask", rifle will ask you what program to run.
+#
 # Prefixing a condition with "!" will negate its result.
 # These conditions are currently supported:
 #   match <regexp> | The regexp matches $1
@@ -177,5 +179,6 @@ label wallpaper, number 13, mime ^image, X = feh --bg-center "$1"
 label wallpaper, number 14, mime ^image, X = feh --bg-fill "$1"
 
 # Define the editor for non-text files + pager as last action
+              !mime ^text, !ext xml|csv|tex|py|pl|rb|sh|php  = ask
 label editor, !mime ^text, !ext xml|csv|tex|py|pl|rb|sh|php  = "$EDITOR" -- "$@"
 label pager,  !mime ^text, !ext xml|csv|tex|py|pl|rb|sh|php  = "$PAGER" -- "$@"
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index cab164be..95a536ef 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -17,7 +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.ext.rifle import squash_flags, ASK_COMMAND
 from ranger.core.shared import FileManagerAware, EnvironmentAware, \
 		SettingsAware
 from ranger.core.tab import Tab
@@ -342,7 +342,8 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 				cf = self.thisfile
 				selection = self.thistab.get_selection()
 				if not self.thistab.enter_dir(cf) and selection:
-					if self.execute_file(selection, mode=mode) is False:
+					result = self.execute_file(selection, mode=mode)
+					if result in (False, ASK_COMMAND):
 						self.open_console('open_with ')
 			elif direction.vertical() and cwd.files:
 				newpos = direction.move(
diff --git a/ranger/ext/rifle.py b/ranger/ext/rifle.py
index 16de09f3..92fbae11 100755
--- a/ranger/ext/rifle.py
+++ b/ranger/ext/rifle.py
@@ -22,6 +22,7 @@ import sys
 
 DEFAULT_PAGER = 'less'
 DEFAULT_EDITOR = 'nano'
+ASK_COMMAND = 'ask'
 ENCODING = 'utf-8'
 
 try:
@@ -292,6 +293,8 @@ class Rifle(object):
 		for count, cmd, lbl, flgs in self.list_commands(files, mimetype):
 			if label and label == lbl or not label and count == number:
 				cmd = self.hook_command_preprocessing(cmd)
+				if cmd == ASK_COMMAND:
+					return ASK_COMMAND
 				command = self._build_command(files, cmd, flags + flgs)
 				break
 			else: