From 19f5ef2dd535656e385e4dfb8801e7e4b8005a22 Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 14 Feb 2011 23:52:00 +0000 Subject: Added --choosefile + doc to replace ornivar's RANGER_RETURN_FILE I recommended environment variables to ornivar because its easier for a quick hack but I wouldn't like to have it in the codebase quite like this. --- ranger/core/helper.py | 4 ++++ ranger/defaults/apps.py | 7 ++++--- ranger/help/invocation.py | 16 ++++++++++++++++ 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= When a filename is supplied, run it with the flags |2| +--choosefile= + 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 . 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 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. -- cgit 1.4.1-2-gfad0