summary refs log tree commit diff stats
path: root/doc/examples/bash_automatic_cd.sh
diff options
context:
space:
mode:
Diffstat (limited to 'doc/examples/bash_automatic_cd.sh')
-rw-r--r--doc/examples/bash_automatic_cd.sh21
1 files changed, 21 insertions, 0 deletions
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"'
l/503manhattan-line.mu.html?h=hlt&id=78357b8852626b510527f3b8d770a7dd8956fcc7'>78357b88 ^
f6fd7e1b ^
dc5a0acf ^

f6fd7e1b ^

372367f5 ^
f6fd7e1b ^
f6fd7e1b ^
78357b88 ^
372367f5 ^
f6fd7e1b ^


78357b88 ^
f6fd7e1b ^




























3350c34a ^
f6fd7e1b ^
4254408a ^




f6fd7e1b ^

4254408a ^
372367f5 ^
f6fd7e1b ^


4254408a ^
3350c34a ^
f6fd7e1b ^



4254408a ^
372367f5 ^
f6fd7e1b ^


4254408a ^
3350c34a ^
f6fd7e1b ^






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