diff options
author | Dmytro Meleshko <dmytro.meleshko@gmail.com> | 2019-10-27 21:25:23 +0200 |
---|---|---|
committer | Dmytro Meleshko <dmytro.meleshko@gmail.com> | 2019-10-27 21:25:53 +0200 |
commit | c915dff4844b99e2759c451215ab3eac70b53ce2 (patch) | |
tree | 65644039a00dbb9c07b65ce2380dbfa1618d8e78 /examples | |
parent | 9614b6cf5e222ac74f0241334ba012c53ce7c838 (diff) | |
download | ranger-c915dff4844b99e2759c451215ab3eac70b53ce2.tar.gz |
Refactored examples/bash_automatic_cd.sh
Diffstat (limited to 'examples')
-rw-r--r-- | examples/bash_automatic_cd.sh | 14 |
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: |