Created
January 20, 2024 06:00
-
-
Save rpetti/9a03ce96b7d06c85a3637812ccbfc6f1 to your computer and use it in GitHub Desktop.
change directory using ranger
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
function ranger-cd { | |
local IFS=$'\t\n' | |
local tempfile="$(mktemp -t tmp.XXXXXX)" | |
local ranger_cmd=( | |
command | |
ranger | |
--cmd="map <enter> chain shell echo %d > "$tempfile"; quitall" | |
) | |
${ranger_cmd[@]} "$@" | |
if [[ -f "$tempfile" ]] && [[ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]]; then | |
cd -- "$(cat "$tempfile")" || return | |
fi | |
command rm -f -- "$tempfile" 2>/dev/null | |
} | |
alias r=ranger-cd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment