about summary refs log tree commit diff stats
path: root/doc/examples
diff options
context:
space:
mode:
Diffstat (limited to 'doc/examples')
-rw-r--r--doc/examples/README8
-rw-r--r--doc/examples/bash_automatic_cd.sh21
-rw-r--r--doc/examples/bash_subshell_notice.sh7
-rw-r--r--doc/examples/plugin_chmod_keybindings.py20
-rw-r--r--doc/examples/plugin_file_filter.py19
-rw-r--r--doc/examples/plugin_hello_world.py23
-rw-r--r--doc/examples/plugin_new_macro.py19
-rw-r--r--doc/examples/plugin_new_sorting_method.py9
-rw-r--r--doc/examples/rifle_different_file_opener.conf9
-rwxr-xr-xdoc/examples/rifle_sxiv.sh48
-rw-r--r--doc/examples/vim_file_chooser.vim17
11 files changed, 200 insertions, 0 deletions
diff --git a/doc/examples/README b/doc/examples/README
new file mode 100644
index 00000000..ca514853
--- /dev/null
+++ b/doc/examples/README
@@ -0,0 +1,8 @@
+The files in this directory contain applications or extensions of ranger which
+are put here for your inspiration and as references.
+
+In order to use a plugin from this directory, you need to copy it to
+~/.config/ranger/plugins/
+
+Note that if you update ranger to a new minor version (for example,
+from 1.6.* to 1.7.0), your outdated plugins WILL break and crash ranger.
diff --git a/doc/examples/bash_automatic_cd.sh b/doc/examples/bash_automatic_cd.sh
new file mode 100644
index 00000000..8d72c553
--- /dev/null
+++ b/doc/examples/bash_automatic_cd.sh
@@ -0,0 +1,21 @@
+# Compatible with ranger 1.4.2 through 1.6.*
+#
+# Automatically change the directory in bash after closing ranger
+#
+# This is a bash function for .bashrc to automatically change the directory to
+# the last visited one after ranger quits.
+# To undo the effect of this function, you can type "cd -" to return to the
+# original directory.
+
+function ranger-cd {
+    tempfile='/tmp/chosendir'
+    /usr/bin/ranger --choosedir="$tempfile" "${@:-$(pwd)}"
+    test -f "$tempfile" &&
+    if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then
+        cd -- "$(cat "$tempfile")"
+    fi
+    rm -f -- "$tempfile"
+}
+
+# This binds Ctrl-O to ranger-cd:
+bind '"\C-o":"ranger-cd\C-m"'
diff --git a/doc/examples/bash_subshell_notice.sh b/doc/examples/bash_subshell_notice.sh
new file mode 100644
index 00000000..bc44d5a8
--- /dev/null
+++ b/doc/examples/bash_subshell_notice.sh
@@ -0,0 +1,7 @@
+# Compatible with ranger 1.5.3 through 1.6.*
+#
+# Change the prompt when you open a shell from inside ranger
+#
+# Add this line to your .bashrc for it to work.
+
+[ -n "$RANGER_LEVEL" ] && PS1="$PS1"'(in ranger) '
diff --git a/doc/examples/plugin_chmod_keybindings.py b/doc/examples/plugin_chmod_keybindings.py
new file mode 100644
index 00000000..0ab975ed
--- /dev/null
+++ b/doc/examples/plugin_chmod_keybindings.py
@@ -0,0 +1,20 @@
+# Compatible with ranger 1.6.*
+#
+# 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/doc/examples/plugin_file_filter.py b/doc/examples/plugin_file_filter.py
new file mode 100644
index 00000000..965fa2e8
--- /dev/null
+++ b/doc/examples/plugin_file_filter.py
@@ -0,0 +1,19 @@
+# Compatible with ranger 1.6.*
+#
+# 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, directory, hidden_filter, name_filter):
+       if hidden_filter and directory.path == '/' and fname in ('boot', 'sbin', 'proc', 'sys'):
+               return False
+       else:
+               return old_accept_file(fname, directory, hidden_filter, name_filter)
+
+# Overwrite the old function
+import ranger.fsobject.directory
+ranger.fsobject.directory.accept_file = custom_accept_file
diff --git a/doc/examples/plugin_hello_world.py b/doc/examples/plugin_hello_world.py
new file mode 100644
index 00000000..a803e21b
--- /dev/null
+++ b/doc/examples/plugin_hello_world.py
@@ -0,0 +1,23 @@
+# Compatible with ranger 1.6.*
+#
+# 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 safe.
+    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/doc/examples/plugin_new_macro.py b/doc/examples/plugin_new_macro.py
new file mode 100644
index 00000000..159a92f2
--- /dev/null
+++ b/doc/examples/plugin_new_macro.py
@@ -0,0 +1,19 @@
+# Compatible with ranger 1.6.*
+#
+# 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/doc/examples/plugin_new_sorting_method.py b/doc/examples/plugin_new_sorting_method.py
new file mode 100644
index 00000000..02abbc47
--- /dev/null
+++ b/doc/examples/plugin_new_sorting_method.py
@@ -0,0 +1,9 @@
+# Compatible with ranger 1.6.*
+#
+# 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/doc/examples/rifle_different_file_opener.conf b/doc/examples/rifle_different_file_opener.conf
new file mode 100644
index 00000000..4a8250b8
--- /dev/null
+++ b/doc/examples/rifle_different_file_opener.conf
@@ -0,0 +1,9 @@
+# Compatible with ranger 1.6.*
+#
+# 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" -- "$@"
diff --git a/doc/examples/rifle_sxiv.sh b/doc/examples/rifle_sxiv.sh
new file mode 100755
index 00000000..6307f1c2
--- /dev/null
+++ b/doc/examples/rifle_sxiv.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+# Compatible with ranger 1.6.*
+#
+# This script searches image files in a directory, opens them all with sxiv and
+# sets the first argument to the first image displayed by sxiv.
+#
+# This is supposed to be used in rifle.conf as a workaround for the fact that
+# sxiv takes no file name arguments for the first image, just the number.  Copy
+# this file somewhere into your $PATH and add this at the top of rifle.conf:
+#
+#   mime ^image, has sxiv, X, flag f = path/to/this/script -- "$@"
+#
+# Implementation notes: this script is quite slow because of POSIX limitations
+# and portability concerns. First calling the shell function 'abspath' is
+# quicker than calling 'realpath' because it would fork a whole process, which
+# is slow. Second, we need to append a file list to sxiv, which can only be done
+# properly in two ways: arrays (which are not POSIX) or \0 sperated
+# strings. Unfortunately, assigning \0 to a variable is not POSIX either (will
+# not work in dash and others), so we cannot store the result of listfiles to a
+# variable.
+
+if [ $# -eq 0 ]; then
+    echo "Usage: ${0##*/} PICTURES"
+    exit
+fi
+
+[ "$1" == '--' ] && shift
+
+abspath () {
+    case "$1" in
+        /*) printf "%s\n" "$1";;
+        *)  printf "%s\n" "$PWD/$1";;
+    esac
+}
+
+listfiles () {
+    find -L "$(dirname "$target")" -maxdepth 1 -type f -iregex \
+      '.*\(jpe?g\|bmp\|png\|gif\)$' -print0 | sort -z
+}
+
+target="$(abspath "$1")"
+count="$(listfiles | grep -m 1 -ZznF "$target" | cut -d: -f1)"
+
+if [ -n "$count" ]; then
+    listfiles | xargs -0 sxiv -n "$count" --
+else
+    sxiv -- "$@" # fallback
+fi
diff --git a/doc/examples/vim_file_chooser.vim b/doc/examples/vim_file_chooser.vim
new file mode 100644
index 00000000..4f5fa3f2
--- /dev/null
+++ b/doc/examples/vim_file_chooser.vim
@@ -0,0 +1,17 @@
+" Compatible with ranger 1.4.2 through 1.6.*
+"
+" Add ranger as a file chooser in vim
+"
+" If you add this function and the key binding to the .vimrc, ranger can be
+" started using the keybinding ",r".  Once you select a file by pressing
+" enter, ranger will quit again and vim will open the selected file.
+
+fun! RangerChooser()
+    exec "silent !ranger --choosefile=/tmp/chosenfile " . expand("%:p:h")
+    if filereadable('/tmp/chosenfile')
+        exec 'edit ' . system('cat /tmp/chosenfile')
+        call system('rm /tmp/chosenfile')
+    endif
+    redraw!
+endfun
+map ,r :call RangerChooser()<CR>
lt;arg@10kloc.org> 2006-08-23 18:50:46 +0200 updated man page' href='/acidbong/suckless/dwm/commit/draw.c?id=7e597ae204ce94398f8c722e335f20d5a4a30c8a'>7e597ae ^
9833610 ^
8a34fa5 ^
9833610 ^
b55bd70 ^
7e597ae ^

c73d5cb ^
4881857 ^
7739e6b ^


6458803 ^
8a34fa5 ^
4881857 ^
7739e6b ^

c73d5cb ^








6e72d78 ^

8a34fa5 ^
bf35794 ^
c09bf8d ^

6b25d06 ^
4688ad1 ^
c09bf8d ^

b355755 ^
c09bf8d ^
b55bd70 ^
78f4b51 ^
c09bf8d ^
78f4b51 ^
e995c1b ^
c09bf8d ^
e995c1b ^
0045ad8 ^
e369292 ^
c09bf8d ^
3c35b90 ^
7e597ae ^

3c35b90 ^
7e597ae ^
0045ad8 ^
2dd5212 ^
7e597ae ^
78f4b51 ^
4688ad1 ^
3c35b90 ^
e6cbe9c ^
c09bf8d ^

9e8b325 ^
ca65478 ^
9e8b325 ^
dc5d967 ^
9e8b325 ^
e81eb46 ^

8a34fa5 ^


8a34fa5 ^
ca65478 ^
d42c3ba ^
d7e1708 ^
8a34fa5 ^
8a8b795 ^
9e8b325 ^


8a34fa5 ^



8a34fa5 ^
9e8b325 ^
8a34fa5 ^


9e8b325 ^







8a34fa5 ^



9e8b325 ^


a308b75 ^
ac6e34e ^
9e8b325 ^

8a34fa5 ^
9e8b325 ^
8a34fa5 ^
adaa28a ^

ca65478 ^
adaa28a ^

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