# Compatible with ranger 1.4.2 through 1.7.* # # 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. ranger-cd() { local temp_file chosen_dir temp_file="$(mktemp)" ranger --choosedir="$temp_file" -- "${@:-$PWD}" if chosen_dir="$(<"$temp_file")" && [[ -n "$chosen_dir" ]]; then cd -- "$chosen_dir" fi rm -f -- "$temp_file" } # This binds Ctrl-O to ranger-cd: bind '"\C-o":"ranger-cd\C-m"'