Forked from dbohdan/Zsh: change directory using ranger
Last active
August 29, 2015 14:27
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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