From c915dff4844b99e2759c451215ab3eac70b53ce2 Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Sun, 27 Oct 2019 21:25:23 +0200 Subject: Refactored examples/bash_automatic_cd.sh --- examples/bash_automatic_cd.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'examples') 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: -- cgit 1.4.1-2-gfad0