Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Enzime/f044c62df869237395c1 to your computer and use it in GitHub Desktop.
Save Enzime/f044c62df869237395c1 to your computer and use it in GitHub Desktop.
Adopted from the "Bash: cd to last path after exit" example in the man page for ranger(1).
ranger-cd() {
tempfile=$(mktemp)
ranger --choosedir="$tempfile" "${@:-$(pwd)}" < $TTY
test -f "$tempfile" &&
if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then
cd -- "$(cat "$tempfile")"
fi
rm -f -- "$tempfile"
# hacky way of transferring over previous command and updating the screen
VISUAL=true zle edit-command-line
}
autoload -U edit-command-line
zle -N edit-command-line
# This binds Ctrl-O to ranger-cd:
zle -N ranger-cd
bindkey '^o' ranger-cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment