summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/core/helper.py4
-rw-r--r--ranger/defaults/apps.py7
-rw-r--r--ranger/help/invocation.py16
3 files changed, 24 insertions, 3 deletions
diff --git a/ranger/core/helper.py b/ranger/core/helper.py
index 3c018192..249b4c5c 100644
--- a/ranger/core/helper.py
+++ b/ranger/core/helper.py
@@ -65,6 +65,10 @@ def parse_arguments():
 	parser.add_option('-f', '--flags', type='string', default='',
 			metavar='string',
 			help="if a filename is supplied, run it with these flags.")
+	parser.add_option('--choosefile', type='string', metavar='TARGET',
+			help="Makes ranger act like a file chooser. When opening "
+			"a file, it will quit and write the name of the selected "
+			"file to TARGET.")
 
 	options, positional = parser.parse_args()
 	arg = OpenStruct(options.__dict__, targets=positional)
diff --git a/ranger/defaults/apps.py b/ranger/defaults/apps.py
index 8c59c57a..7926bbba 100644
--- a/ranger/defaults/apps.py
+++ b/ranger/defaults/apps.py
@@ -46,6 +46,7 @@ This example modifies the behaviour of "feh" and adds a custom media player:
 #### end of the example
 """
 
+import ranger
 from ranger.api.apps import *
 from ranger.ext.get_executables import get_executables
 
@@ -54,9 +55,9 @@ class CustomApplications(Applications):
 		"""How to determine the default application?"""
 		f = c.file
 
-		return_file = os.getenv("RANGER_RETURN_FILE")
-		if return_file is not None:
-			open(return_file, 'w').write(f.path)
+		# ranger can act as a file chooser when running with --choosefile=...
+		if ranger.arg.choosefile:
+			open(ranger.arg.choosefile, 'w').write(f.path)
 			raise SystemExit()
 
 		if f.basename.lower() == 'makefile':
diff --git a/ranger/help/invocation.py b/ranger/help/invocation.py
index 688308f1..75d2330e 100644
--- a/ranger/help/invocation.py
+++ b/ranger/help/invocation.py
@@ -64,6 +64,22 @@ command line.
 -f <flags>, --flags=<flags>
       When a filename is supplied, run it with the flags <flags> |2|
 
+--choosefile=<target>
+      Makes ranger act like a file choser. When opneing a file, it will
+      quit and write the name of the selected file to the filename specified
+      as <target>. This file can be read in a script and used to open a
+      certain file which has been chosen with ranger.
+
+      Here, for instance, is a vim script that uses ranger in vim to open files:
+
+      fun Ranger()
+        silent !ranger --choosefile=/tmp/chosen
+        exec 'edit ' . system('cat /tmp/chosen')
+        call system('rm /tmp/chosen')
+        redraw!
+      endfun
+      map <leader>r :call Ranger()
+
 (Optional) Positional Argument
       The positional argument should be a path to the directory you
       want ranger to start in, or the file which you want to run.