Skip to content

Instantly share code, notes, and snippets.

@rpetti
Created January 20, 2024 06:00
Show Gist options
  • Save rpetti/9a03ce96b7d06c85a3637812ccbfc6f1 to your computer and use it in GitHub Desktop.
Save rpetti/9a03ce96b7d06c85a3637812ccbfc6f1 to your computer and use it in GitHub Desktop.
change directory using ranger
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