summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--README9
-rw-r--r--ranger/core/fm.py2
-rw-r--r--ranger/core/helper.py3
-rw-r--r--ranger/help/invocation.py4
4 files changed, 13 insertions, 5 deletions
diff --git a/README b/README
index c1462ec3..cf0e3577 100644
--- a/README
+++ b/README
@@ -96,12 +96,11 @@ Combine Ranger With Other Applications
 Add this to your ~/.bashrc to use ranger as a directory switcher:
 
 function ranger-cd {
-  before="$(pwd)"
-  python2.6 /the/path/to/ranger/ranger.py --fail-unless-cd "$@" || return 0
-  after="$(grep \^\' ~/.config/ranger/bookmarks | cut -b3-)"
-  if [[ "$before" != "$after" ]]; then
-    cd "$after"
+  ranger --choosedir=/tmp/chosen
+  if [ -f /tmp/chosen -a "$(cat /tmp/chosen)" != "$(pwd | tr -d "\n")" ]; then
+    cd "$(cat /tmp/chosen)"
   fi
+  rm -f /tmp/chosen
 }
 bind '"\C-o":"ranger-cd\C-m"'
 
diff --git a/ranger/core/fm.py b/ranger/core/fm.py
index 116717ca..ec2fbdbb 100644
--- a/ranger/core/fm.py
+++ b/ranger/core/fm.py
@@ -212,5 +212,7 @@ class FM(Actions, SignalDispatcher):
 			raise SystemExit
 
 		finally:
+			if ranger.arg.choosedir and self.env.cwd and self.env.cwd.path:
+				open(ranger.arg.choosedir, 'w').write(self.env.cwd.path)
 			self.bookmarks.remember(env.cwd)
 			self.bookmarks.save()
diff --git a/ranger/core/helper.py b/ranger/core/helper.py
index 249b4c5c..cb0afefe 100644
--- a/ranger/core/helper.py
+++ b/ranger/core/helper.py
@@ -69,6 +69,9 @@ def parse_arguments():
 			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.")
+	parser.add_option('--choosedir', type='string', metavar='TARGET',
+			help="Makes ranger act like a directory chooser. When ranger quits"
+			", it will write the name of the last visited directory to TARGET")
 
 	options, positional = parser.parse_args()
 	arg = OpenStruct(options.__dict__, targets=positional)
diff --git a/ranger/help/invocation.py b/ranger/help/invocation.py
index c4a06543..afb1cd27 100644
--- a/ranger/help/invocation.py
+++ b/ranger/help/invocation.py
@@ -70,6 +70,10 @@ command line.
       as <target>. This file can be read in a script and used to open a
       certain file which has been chosen with ranger.
 
+--choosedir=<target>
+      Makes ranger act like a directory chooser. When ranger quits, it will
+      write the name of the last visited directory to <target>
+
 (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.
?h=v1.9.1&id=4e01caf19cfbc798862e6b8b2dbd77328c8f99a2'>^
4c13e1f2 ^

f07bb12f ^



f07bb12f ^















4c13e1f2 ^











f07bb12f ^
4e9450f9 ^
f07bb12f ^


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