about summary refs log tree commit diff stats
path: root/examples/bash_automatic_cd.sh
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2012-08-06 06:32:04 +0200
committerhut <hut@lavabit.com>2012-08-06 06:39:26 +0200
commit796074b541aaca459c594fe517c11d275778eef6 (patch)
tree0cc5c6450625a97a3375d6856b4ef07ca581ecdf /examples/bash_automatic_cd.sh
parent13cb3fc49c07ba45f12508000ac615ff2e9b3e23 (diff)
downloadranger-796074b541aaca459c594fe517c11d275778eef6.tar.gz
added the examples from the man page to the examples directory
I guess a whole directory for examples scales better than having them in
the man page.
Diffstat (limited to 'examples/bash_automatic_cd.sh')
-rw-r--r--examples/bash_automatic_cd.sh19
1 files changed, 19 insertions, 0 deletions
diff --git a/examples/bash_automatic_cd.sh b/examples/bash_automatic_cd.sh
new file mode 100644
index 00000000..a63280d1
--- /dev/null
+++ b/examples/bash_automatic_cd.sh
@@ -0,0 +1,19 @@
+# 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"'
58'>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