diff --git a/hosts/home.nix b/hosts/home.nix index 3c2d6fa..b77f3d3 100644 --- a/hosts/home.nix +++ b/hosts/home.nix @@ -90,9 +90,28 @@ in goops = "g reset --soft HEAD^"; v = "vim"; + r = "ranger"; rm = "trash-put"; }; + # Change to directory when exiting ranger with Q + # https://github.com/ranger/ranger/issues/1554#issuecomment-491650123 bashrcExtra = '' + function ranger { + local IFS=$'\t\n' + local tempfile="$(mktemp -t tmp.XXXXXX)" + local ranger_cmd=( + command + ranger + --cmd="map Q 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 + } + pfetch while true; do f=`fortune`