summary refs log tree commit diff stats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/README2
-rw-r--r--examples/plugin_chmod_keybindings.py18
-rw-r--r--examples/plugin_file_filter.py17
-rw-r--r--examples/plugin_hello_world.py21
-rw-r--r--examples/plugin_new_macro.py17
-rw-r--r--examples/plugin_new_sorting_method.py7
-rw-r--r--examples/plugin_skip_default_rc.py9
-rw-r--r--examples/rifle_different_file_opener.conf7
8 files changed, 97 insertions, 1 deletions
diff --git a/examples/README b/examples/README
index 60f29ac6..8606a89d 100644
--- a/examples/README
+++ b/examples/README
@@ -1,2 +1,2 @@
-Thes files in this directory contain applications or extensions of ranger which
+The files in this directory contain applications or extensions of ranger which
 are put here for your inspiration and as references.
diff --git a/examples/plugin_chmod_keybindings.py b/examples/plugin_chmod_keybindings.py
new file mode 100644
index 00000000..62ca6c58
--- /dev/null
+++ b/examples/plugin_chmod_keybindings.py
@@ -0,0 +1,18 @@
+# This plugin serves as an example for adding key bindings through a plugin.
+# It could replace the ten lines in the rc.conf that create the key bindings
+# for the "chmod" command.
+
+import ranger.api
+old_hook_init = ranger.api.hook_init
+
+def hook_init(fm):
+	old_hook_init(fm)
+
+	# Generate key bindings for the chmod command
+	command = "map {0}{1}{2} shell -d chmod {1}{0}{2} %s"
+	for	mode in list('ugoa') + '':
+		for	perm in "rwxXst":
+			fm.execute_console(command.format('-', mode, perm))
+			fm.execute_console(command.format('+', mode, perm))
+
+ranger.api.hook_init = hook_init
diff --git a/examples/plugin_file_filter.py b/examples/plugin_file_filter.py
new file mode 100644
index 00000000..99d026bb
--- /dev/null
+++ b/examples/plugin_file_filter.py
@@ -0,0 +1,17 @@
+# This plugin hides the directories "boot", "sbin", "proc" and "sys" in the
+# root directory.
+
+# Save the original filter function
+import ranger.fsobject.directory
+old_accept_file = ranger.fsobject.directory.accept_file
+
+# Define a new one
+def custom_accept_file(fname, mypath, hidden_filter, name_filter):
+       if hidden_filter and mypath == '/' and fname in ('boot', 'sbin', 'proc', 'sys'):
+               return False
+       else:
+               return old_accept_file(fname, mypath, hidden_filter, name_filter)
+
+# Overwrite the old function
+import ranger.fsobject.directory
+ranger.fsobject.directory.accept_file = custom_accept_file
diff --git a/examples/plugin_hello_world.py b/examples/plugin_hello_world.py
new file mode 100644
index 00000000..187f428e
--- /dev/null
+++ b/examples/plugin_hello_world.py
@@ -0,0 +1,21 @@
+# This is a sample plugin that displays "Hello World" in ranger's console after
+# it started.
+
+# We are going to extend the hook "ranger.api.hook_ready", so first we need
+# to import ranger.api:
+import ranger.api
+
+# Save the previously existing hook, because maybe another module already
+# extended that hook and we don't want to lose it:
+old_hook_ready = ranger.api.hook_ready
+
+# Create a replacement for the hook that...
+def hook_ready(fm):
+  # ...does the desired action...
+  fm.notify("Hello World")
+  # ...and calls the saved hook.  If you don't care about the return value, simply
+  # return the return value of the previous hook to be on the safe side.
+  return old_hook_ready(fm)
+
+# Finally, "monkey patch" the existing hook_ready function with our replacement:
+ranger.api.hook_ready = hook_ready
diff --git a/examples/plugin_new_macro.py b/examples/plugin_new_macro.py
new file mode 100644
index 00000000..ec0c487c
--- /dev/null
+++ b/examples/plugin_new_macro.py
@@ -0,0 +1,17 @@
+# This plugin adds the new macro %date which is substituted with the current
+# date in commands that allow macros.  You can test it with the command
+# ":shell echo %date; read"
+
+# Save the original macro function
+import ranger.core.actions
+old_get_macros = ranger.core.actions.Actions._get_macros
+
+# Define a new macro function
+import time
+def get_macros_with_date(self):
+       macros = old_get_macros(self)
+       macros['date'] = time.strftime('%m/%d/%Y')
+       return macros
+
+# Overwrite the old one
+ranger.core.actions.Actions._get_macros = get_macros_with_date
diff --git a/examples/plugin_new_sorting_method.py b/examples/plugin_new_sorting_method.py
new file mode 100644
index 00000000..2500c1c1
--- /dev/null
+++ b/examples/plugin_new_sorting_method.py
@@ -0,0 +1,7 @@
+# This plugin adds the sorting algorithm called 'random'.  To enable it, type
+# ":set sort=random" or create a key binding with ":map oz set sort=random"
+
+from ranger.fsobject.directory import Directory
+from random import random
+Directory.sort_dict['random'] = lambda path: random()
+
diff --git a/examples/plugin_skip_default_rc.py b/examples/plugin_skip_default_rc.py
new file mode 100644
index 00000000..6a657a99
--- /dev/null
+++ b/examples/plugin_skip_default_rc.py
@@ -0,0 +1,9 @@
+# This plugin inhibits the loading of the default rc.conf.  This serves to
+# speed up starting time by avoiding to load rc.conf twice if you have a full
+# copy of it in ~/.config/ranger.
+#
+# Don't use this if you have a supplementary rc.conf or no rc.conf at all, or
+# you will end up without key bindings and options.
+
+import ranger.core.main
+ranger.core.main.load_default_config = False
diff --git a/examples/rifle_different_file_opener.conf b/examples/rifle_different_file_opener.conf
new file mode 100644
index 00000000..1362a1eb
--- /dev/null
+++ b/examples/rifle_different_file_opener.conf
@@ -0,0 +1,7 @@
+# Replace your rifle.conf with this file to use xdg-open as your file opener.
+# This is, of course, adaptable for use with any other file opener.
+else = xdg-open "$1"
+
+# You need an "editor" and "pager" in order to use certain functions in ranger:
+label editor = "$EDITOR" -- "$@"
+label pager  = "$PAGER" -- "$@"
3trace.cc?h=main&id=1f852acc8fa14d531802eed04761b93112668c1e'>^
c442a5ad ^
7feea75b ^
c442a5ad ^

51530916 ^
c442a5ad ^

d51abbf1 ^
c442a5ad ^

d51abbf1 ^
c442a5ad ^





















c442a5ad ^



c442a5ad ^















51530916 ^

6e1eeeeb ^











c69f3314 ^
6e1eeeeb ^

c442a5ad ^










6e1eeeeb ^
c442a5ad ^











6e1eeeeb ^








c442a5ad ^

fd6d8612 ^



aa2fd725 ^
c442a5ad ^
90e6596f ^
c442a5ad ^
8359e579 ^
6e1eeeeb ^
c442a5ad ^

aa2fd725 ^
c442a5ad ^

fd6d8612 ^





4a943d4e ^
fd6d8612 ^
c442a5ad ^



51530916 ^
c442a5ad ^












6e1eeeeb ^
8cf59120 ^
1ba81b0f ^
6e1eeeeb ^

1ba81b0f ^
6e1eeeeb ^
8359e579 ^

6e1eeeeb ^
8359e579 ^
6e1eeeeb ^

8359e579 ^

6e1eeeeb ^



8359e579 ^


6e1eeeeb ^
8359e579 ^





c442a5ad ^

b5ab709c ^
4a943d4e ^
c442a5ad ^








1ba81b0f ^
c442a5ad ^
93d4cc93 ^


c442a5ad ^
1ba81b0f ^
c442a5ad ^















51530916 ^
baaf6d65 ^
5af83346 ^

c442a5ad ^
4e39c6bb ^

60c566ea ^
4e39c6bb ^






c442a5ad ^








4a943d4e ^
c442a5ad ^
4e39c6bb ^
fd6d8612 ^
2e72dc12 ^
60c566ea ^
06584c52 ^
4a943d4e ^
b24eb476 ^
ac0e9db5 ^
51530916 ^
ac0e9db5 ^
41f5188d ^

6c96a437 ^
f72f34d3 ^
6e1eeeeb ^

51530916 ^
ac0e9db5 ^
51530916 ^
ac0e9db5 ^
41f5188d ^
51530916 ^

f72f34d3 ^







51530916 ^



c442a5ad ^




f72f34d3 ^
c442a5ad ^
f72f34d3 ^

41f5188d ^

51530916 ^

41f5188d ^
b5ab709c ^
51530916 ^
6c96a437 ^
41f5188d ^
e9445310 ^
51530916 ^
eba30983 ^
51530916 ^



75ab8732 ^


6c96a437 ^
75ab8732 ^







c442a5ad ^










51530916 ^

c442a5ad ^



8cf59120 ^
c442a5ad ^
51530916 ^

51530916 ^

ac0e9db5 ^
51530916 ^
ac0e9db5 ^

51530916 ^


7be15b8b ^
51530916 ^




7be15b8b ^








c442a5ad ^


4a943d4e ^
c442a5ad ^













c442a5ad ^

065c0184 ^


ab02bb66 ^
c442a5ad ^

90e6596f ^
6e1eeeeb ^
14a06183 ^
d260b017 ^
c442a5ad ^




90e6596f ^
c442a5ad ^









6e1eeeeb ^
c442a5ad ^


8359e579 ^











c442a5ad ^


d7494165 ^












51530916 ^
385ff136 ^
51530916 ^
385ff136 ^
51530916 ^
385ff136 ^
2fb94e3c ^
51530916 ^
385ff136 ^
51530916 ^


385ff136 ^
51530916 ^

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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523