about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDmytro Meleshko <dmytro.meleshko@gmail.com>2019-10-27 22:07:24 +0200
committerDmytro Meleshko <dmytro.meleshko@gmail.com>2019-10-27 22:09:57 +0200
commit65cf599607f1d125272a4ba3b63ac55ac74a0e43 (patch)
tree3d070e2d1e340c7b931007b5d989e86e5d817f7f
parentc8716e260e961c12b4b51acd805069de6e2d1f8e (diff)
downloadranger-65cf599607f1d125272a4ba3b63ac55ac74a0e43.tar.gz
Refactor the shell script embedded in ranger.py
-rwxr-xr-xranger.py19
1 files 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)