From 65cf599607f1d125272a4ba3b63ac55ac74a0e43 Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Sun, 27 Oct 2019 22:07:24 +0200 Subject: Refactor the shell script embedded in ranger.py --- ranger.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/ranger.py b/ranger.py index 3c4b0f01..57e2b082 100755 --- a/ranger.py +++ b/ranger.py @@ -9,17 +9,18 @@ # default is simply "ranger". (Not this file itself!) # The other arguments are passed to ranger. """": -tempfile="$(mktemp -t tmp.XXXXXX)" +temp_file="$(mktemp)" ranger="${1:-ranger}" -test -z "$1" || shift -"$ranger" --choosedir="$tempfile" "${@:-$(pwd)}" -returnvalue=$? -test -f "$tempfile" && -if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then - cd "$(cat "$tempfile")" +if [ -n "$1" ]; then + shift fi -rm -f -- "$tempfile" -return $returnvalue +"$ranger" --choosedir="$temp_file" -- "${@:-$PWD}" +return_value="$?" +if chosen_dir="$(cat "$temp_file")" && [ -n "$chosen_dir" ]; then + cd -- "$chosen_dir" +fi +rm -f -- "$temp_file" +return "$return_value" """ from __future__ import (absolute_import, division, print_function) -- cgit 1.4.1-2-gfad0