summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2011-02-14 23:52:00 +0000
committerhut <hut@lavabit.com>2011-02-14 23:52:00 +0000
commit19f5ef2dd535656e385e4dfb8801e7e4b8005a22 (patch)
tree7542188defc7ad6d556bd64cf4cddaf111f07fd6
parente5d250baf62c52267a10e326da52a65710e739c2 (diff)
downloadranger-19f5ef2dd535656e385e4dfb8801e7e4b8005a22.tar.gz
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.
-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.
='alt'>
5fd44f5a ^
0128bee7 ^
d46a05a8 ^
c6953a55 ^
25d023b3 ^
3de15ddd ^
d528952a ^
3de15ddd ^
1c1b6c31 ^
16246965 ^

20f94973 ^
a1d7ed6e ^
0c0b9489 ^
1c1b6c31 ^
9506fb8e ^
6f43de0a ^
a1d7ed6e ^
20f94973 ^
227f75db ^
7a3a429c ^
b76bb9a1 ^
227f75db ^
fa704bab ^
4f1a6e67 ^
ca202490 ^
a99d5019 ^


70f876d5 ^



a1d7ed6e ^

a1d7ed6e ^
0128bee7 ^


a4570538 ^
f2d8598d ^
0128bee7 ^
f2d8598d ^
0a1bc759 ^
0c0b9489 ^

0128bee7 ^
a4570538 ^
20f94973 ^
0c0b9489 ^
7b6fab79 ^
0c0b9489 ^

c2238598 ^


fdd39045 ^
c2238598 ^
a9f69385 ^

6b3a30d7 ^


42ae9500 ^














16246965 ^



be7c282c ^




48e7ddd8 ^
a0ca73c8 ^
48e7ddd8 ^
a0ca73c8 ^

48e7ddd8 ^




a0ca73c8 ^
48e7ddd8 ^
a0ca73c8 ^

48e7ddd8 ^














8e0d73b5 ^
a4570538 ^










a1d7ed6e ^
ad1a4204 ^

b4b0eb24 ^
ad1a4204 ^



b4b0eb24 ^
a1d7ed6e ^
f8e96a97 ^

871c502d ^

361781cd ^


361781cd ^


ab8c4847 ^
361781cd ^
f2d8598d ^

361781cd ^



0cfc59d6 ^
361781cd ^
0cfc59d6 ^
361781cd ^
0cfc59d6 ^
361781cd ^
0cfc59d6 ^
7626fd1d ^
0cfc59d6 ^
ab8c4847 ^




0cfc59d6 ^


fc5d8640 ^

0cfc59d6 ^
3937f010 ^


0a16f0da ^
3937f010 ^
f2d8598d ^
d008817c ^
e6816822 ^

d008817c ^
1ef0ade5 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219