From 1513c012d70e97bd4d352a79763347c117bfa8e6 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Sat, 7 Jan 2023 18:24:59 -0800 Subject: [PATCH] Improve ranger --- hosts/home.nix | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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`