about summary refs log tree commit diff stats
path: root/examples
diff options
context:
space:
mode:
authorDmytro Meleshko <dmytro.meleshko@gmail.com>2019-10-27 21:25:23 +0200
committerDmytro Meleshko <dmytro.meleshko@gmail.com>2019-10-27 21:25:53 +0200
commitc915dff4844b99e2759c451215ab3eac70b53ce2 (patch)
tree65644039a00dbb9c07b65ce2380dbfa1618d8e78 /examples
parent9614b6cf5e222ac74f0241334ba012c53ce7c838 (diff)
downloadranger-c915dff4844b99e2759c451215ab3eac70b53ce2.tar.gz
Refactored examples/bash_automatic_cd.sh
Diffstat (limited to 'examples')
-rw-r--r--examples/bash_automatic_cd.sh14
1 files changed, 7 insertions, 7 deletions
diff --git a/examples/bash_automatic_cd.sh b/examples/bash_automatic_cd.sh
index 04b58e24..c143c68c 100644
--- a/examples/bash_automatic_cd.sh
+++ b/examples/bash_automatic_cd.sh
@@ -7,14 +7,14 @@
 # To undo the effect of this function, you can type "cd -" to return to the
 # original directory.
 
-function ranger-cd {
-    tempfile="$(mktemp -t tmp.XXXXXX)"
-    ranger --choosedir="$tempfile" "${@:-$(pwd)}"
-    test -f "$tempfile" &&
-    if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then
-        cd -- "$(cat "$tempfile")"
+ranger-cd() {
+    local temp_file chosen_dir
+    temp_file="$(mktemp -t tmp.XXXXXX)"
+    ranger --choosedir="$temp_file" -- "${@:-$PWD}"
+    if chosen_dir="$(<"$temp_file")" && [[ -n "$chosen_dir" ]]; then
+        cd -- "$chosen_dir"
     fi
-    rm -f -- "$tempfile"
+    rm -f -- "$temp_file"
 }
 
 # This binds Ctrl-O to ranger-cd: