summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--README2
-rw-r--r--TODO2
-rw-r--r--doc/ranger.16
-rwxr-xr-xranger.py2
-rw-r--r--ranger/__main__.py5
5 files changed, 12 insertions, 5 deletions
diff --git a/README b/README
index 4ce3462e..96b7e53e 100644
--- a/README
+++ b/README
@@ -147,7 +147,7 @@ Tips
 Change the directory of your parent shell when you exit ranger:
 
 ranger() {
-    command ranger $@ &&
+    command ranger --fail-if-run $@ &&
     cd "$(grep \^\' ~/.ranger/bookmarks | cut -b3-)"
 }
 
diff --git a/TODO b/TODO
index 48651888..1107dee9 100644
--- a/TODO
+++ b/TODO
@@ -74,7 +74,7 @@ Bugs
    (X) #54  10/01/23  max_dirsize_for_autopreview not working
    ( ) #60  10/02/05  utf support improvable
    (X) #62  10/02/15  curs_set can raise an exception
-   ( ) #65  10/02/16  "source ranger ranger some/file.txt" shouldn't cd after exit
+   (X) #65  10/02/16  "source ranger ranger some/file.txt" shouldn't cd after exit
    (X) #67  10/03/08  terminal title in tty
    (X) #69  10/03/11  tab-completion breaks with Apps subclass
    (X) #73  10/03/21  when clicking on the first column, it goes 1x down
diff --git a/doc/ranger.1 b/doc/ranger.1
index 68353dd9..b197d774 100644
--- a/doc/ranger.1
+++ b/doc/ranger.1
@@ -33,6 +33,10 @@ Activate the clean mode:  Ranger will not access or create any configuration
 files nor will it leave any traces on your system.  This is useful when
 your configuration is broken, when you want to avoid clutter, etc.
 .TP
+--fail-if-run
+Return the exit code 1 if ranger is used to run a file, for example with
+`ranger --fail-if-run filename`.  This can be useful for scripts.
+.TP
 -r \fIdir\fR, --confdir=\fIdir\fR
 Define a different configuration directory.  The default is $HOME/.ranger.
 .TP
@@ -172,7 +176,7 @@ of your parent shell after exiting ranger:
 .nf
 
 ranger() {
-    command ranger $@ &&
+    command ranger --fail-if-run $@ &&
     cd "$(grep \\^\\' ~/.ranger/bookmarks | cut -b3-)"
 }
 .\"-----------------------------------------
diff --git a/ranger.py b/ranger.py
index 06b86531..754f0a8f 100755
--- a/ranger.py
+++ b/ranger.py
@@ -23,7 +23,7 @@
 # after you exit ranger by starting it with: source ranger ranger
 """":
 if [ $1 ]; then
-	$@ && cd "$(grep \^\' ~/.ranger/bookmarks | cut -b3-)"
+	$@ --fail-if-run && cd "$(grep \^\' ~/.ranger/bookmarks | cut -b3-)"
 else
 	echo "usage: source path/to/ranger.py path/to/ranger.py"
 fi
diff --git a/ranger/__main__.py b/ranger/__main__.py
index 0814565f..8bb0bfa1 100644
--- a/ranger/__main__.py
+++ b/ranger/__main__.py
@@ -45,6 +45,9 @@ def parse_arguments():
 			help="activate debug mode")
 	parser.add_option('-c', '--clean', action='store_true',
 			help="don't touch/require any config files. ")
+	parser.add_option('--fail-if-run', action='store_true',
+			help="experimental: return the exit code 1 if ranger is" \
+					"used to run a file (with `ranger filename`)")
 	parser.add_option('-r', '--confdir', type='string',
 			metavar='dir', default=DEFAULT_CONFDIR,
 			help="the configuration directory. (%default)")
@@ -178,7 +181,7 @@ def main():
 			runner = Runner(logfunc=print_function)
 			load_apps(runner, ranger.arg.clean)
 			runner(files=[File(target)], mode=arg.mode, flags=arg.flags)
-			sys.exit(0)
+			sys.exit(1 if arg.fail_if_run else 0)
 		else:
 			path = target
 	else:
d=61c025b11ed4ddd002f09f061fd77c75d8b6d0ba'>^
c842d90b ^
2f02189d ^











298f8065 ^
2f02189d ^

c842d90b ^
2f02189d ^









c842d90b ^
2f02189d ^


44c1aeef ^
2f02189d ^
















2f02189d ^



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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260