Should I dual ranger/cleric or wait for the THAC0 bonus?
[ranger.git] / examples / bash_automatic_cd.sh
blobac96ea1227f49e9ef616ce1339b39fc5267c4bf6
1 # Compatible with ranger 1.4.2 through 1.7.*
3 # Automatically change the directory in bash after closing ranger
5 # This is a bash function for .bashrc to automatically change the directory to
6 # the last visited one after ranger quits.
7 # To undo the effect of this function, you can type "cd -" to return to the
8 # original directory.
10 function ranger-cd {
11 tempfile="$(mktemp)"
12 /usr/bin/ranger --choosedir="$tempfile" "${@:-$(pwd)}"
13 test -f "$tempfile" &&
14 if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then
15 cd -- "$(cat "$tempfile")"
17 rm -f -- "$tempfile"
20 # This binds Ctrl-O to ranger-cd:
21 bind '"\C-o":"ranger-cd\C-m"'