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/bash_automatic_cd.sh') 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 From c8716e260e961c12b4b51acd805069de6e2d1f8e Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Sun, 27 Oct 2019 21:53:50 +0200 Subject: Removed unnecessary arguments for mktemp in examples/bash_automatic_cd.sh --- examples/bash_automatic_cd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/bash_automatic_cd.sh') diff --git a/examples/bash_automatic_cd.sh b/examples/bash_automatic_cd.sh index c143c68c..0ab0ec13 100644 --- a/examples/bash_automatic_cd.sh +++ b/examples/bash_automatic_cd.sh @@ -9,7 +9,7 @@ ranger-cd() { local temp_file chosen_dir - temp_file="$(mktemp -t tmp.XXXXXX)" + temp_file="$(mktemp)" ranger --choosedir="$temp_file" -- "${@:-$PWD}" if chosen_dir="$(<"$temp_file")" && [[ -n "$chosen_dir" ]]; then cd -- "$chosen_dir" -- cgit 1.4.1-2-gfad0 From e7fa9d9d694daf5722cef2a929bc2681fc9bff75 Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Mon, 28 Oct 2019 12:07:36 +0200 Subject: Added pattern for mktemp back --- examples/bash_automatic_cd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/bash_automatic_cd.sh') diff --git a/examples/bash_automatic_cd.sh b/examples/bash_automatic_cd.sh index 0ab0ec13..642d6f29 100644 --- a/examples/bash_automatic_cd.sh +++ b/examples/bash_automatic_cd.sh @@ -9,7 +9,7 @@ ranger-cd() { local temp_file chosen_dir - temp_file="$(mktemp)" + temp_file="$(mktemp -t "${0}.XXXXXXXXXX")" ranger --choosedir="$temp_file" -- "${@:-$PWD}" if chosen_dir="$(<"$temp_file")" && [[ -n "$chosen_dir" ]]; then cd -- "$chosen_dir" -- cgit 1.4.1-2-gfad0 From c86a80ca75fd54ada54f0abc4cd71e7fda87d7a3 Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Mon, 28 Oct 2019 12:09:09 +0200 Subject: Replaced `[[` with POSIX-compatible `[` --- examples/bash_automatic_cd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/bash_automatic_cd.sh') diff --git a/examples/bash_automatic_cd.sh b/examples/bash_automatic_cd.sh index 642d6f29..8bf58a9f 100644 --- a/examples/bash_automatic_cd.sh +++ b/examples/bash_automatic_cd.sh @@ -11,7 +11,7 @@ ranger-cd() { local temp_file chosen_dir temp_file="$(mktemp -t "${0}.XXXXXXXXXX")" ranger --choosedir="$temp_file" -- "${@:-$PWD}" - if chosen_dir="$(<"$temp_file")" && [[ -n "$chosen_dir" ]]; then + if chosen_dir="$(<"$temp_file")" && [ -n "$chosen_dir" ]; then cd -- "$chosen_dir" fi rm -f -- "$temp_file" -- cgit 1.4.1-2-gfad0 From 458e8d1812153b7ea8f78d7987f99b02a5ac05fc Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Mon, 28 Oct 2019 12:42:54 +0200 Subject: Added comparison with $PWD back --- examples/bash_automatic_cd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/bash_automatic_cd.sh') diff --git a/examples/bash_automatic_cd.sh b/examples/bash_automatic_cd.sh index 8bf58a9f..0f09079d 100644 --- a/examples/bash_automatic_cd.sh +++ b/examples/bash_automatic_cd.sh @@ -11,7 +11,7 @@ ranger-cd() { local temp_file chosen_dir temp_file="$(mktemp -t "${0}.XXXXXXXXXX")" ranger --choosedir="$temp_file" -- "${@:-$PWD}" - if chosen_dir="$(<"$temp_file")" && [ -n "$chosen_dir" ]; then + if chosen_dir="$(<"$temp_file")" && [ -n "$chosen_dir" ] && [ "$chosen_dir" != "$PWD" ]; then cd -- "$chosen_dir" fi rm -f -- "$temp_file" -- cgit 1.4.1-2-gfad0 From fa670720e20212c70b19b1b7949ae0c36763c819 Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Mon, 28 Oct 2019 12:45:25 +0200 Subject: Removed replaced $(<...) with cat --- examples/bash_automatic_cd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/bash_automatic_cd.sh') diff --git a/examples/bash_automatic_cd.sh b/examples/bash_automatic_cd.sh index 0f09079d..4e505327 100644 --- a/examples/bash_automatic_cd.sh +++ b/examples/bash_automatic_cd.sh @@ -11,7 +11,7 @@ ranger-cd() { local temp_file chosen_dir temp_file="$(mktemp -t "${0}.XXXXXXXXXX")" ranger --choosedir="$temp_file" -- "${@:-$PWD}" - if chosen_dir="$(<"$temp_file")" && [ -n "$chosen_dir" ] && [ "$chosen_dir" != "$PWD" ]; then + if chosen_dir="$(cat "$temp_file")" && [ -n "$chosen_dir" ] && [ "$chosen_dir" != "$PWD" ]; then cd -- "$chosen_dir" fi rm -f -- "$temp_file" -- cgit 1.4.1-2-gfad0 From 4f6edb554e447eb8e10143879be6306e172630f3 Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Mon, 28 Oct 2019 12:53:36 +0200 Subject: Apply requested changes to ranger.py and enforce full POSIX compliance --- examples/bash_automatic_cd.sh | 7 +++---- ranger.py | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'examples/bash_automatic_cd.sh') diff --git a/examples/bash_automatic_cd.sh b/examples/bash_automatic_cd.sh index 4e505327..5ba9d942 100644 --- a/examples/bash_automatic_cd.sh +++ b/examples/bash_automatic_cd.sh @@ -7,11 +7,10 @@ # To undo the effect of this function, you can type "cd -" to return to the # original directory. -ranger-cd() { - local temp_file chosen_dir - temp_file="$(mktemp -t "${0}.XXXXXXXXXX")" +ranger_cd() { + temp_file="$(mktemp -t "ranger_cd.XXXXXXXXXX")" ranger --choosedir="$temp_file" -- "${@:-$PWD}" - if chosen_dir="$(cat "$temp_file")" && [ -n "$chosen_dir" ] && [ "$chosen_dir" != "$PWD" ]; then + if chosen_dir="$(cat -- "$temp_file")" && [ -n "$chosen_dir" ] && [ "$chosen_dir" != "$PWD" ]; then cd -- "$chosen_dir" fi rm -f -- "$temp_file" diff --git a/ranger.py b/ranger.py index 57e2b082..7160160f 100755 --- a/ranger.py +++ b/ranger.py @@ -9,14 +9,14 @@ # default is simply "ranger". (Not this file itself!) # The other arguments are passed to ranger. """": -temp_file="$(mktemp)" +temp_file="$(mktemp -t "ranger_cd.XXXXXXXXXX")" ranger="${1:-ranger}" if [ -n "$1" ]; then - shift + shift fi "$ranger" --choosedir="$temp_file" -- "${@:-$PWD}" return_value="$?" -if chosen_dir="$(cat "$temp_file")" && [ -n "$chosen_dir" ]; then +if chosen_dir="$(cat -- "$temp_file")" && [ -n "$chosen_dir" ] && [ "$chosen_dir" != "$PWD" ]; then cd -- "$chosen_dir" fi rm -f -- "$temp_file" -- cgit 1.4.1-2-gfad0 From 9658e1127aa1b451b1a92d7d911b83b2c5c95d7d Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Sat, 2 Nov 2019 15:20:12 +0200 Subject: Added shebangs and removed notices specifically about Bash --- examples/bash_automatic_cd.sh | 8 +++++--- examples/bash_subshell_notice.sh | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'examples/bash_automatic_cd.sh') diff --git a/examples/bash_automatic_cd.sh b/examples/bash_automatic_cd.sh index 5ba9d942..294f3aaa 100644 --- a/examples/bash_automatic_cd.sh +++ b/examples/bash_automatic_cd.sh @@ -1,9 +1,11 @@ +#!/bin/sh + # Compatible with ranger 1.4.2 through 1.7.* # -# Automatically change the directory in bash after closing ranger +# Automatically change the current working directory after closing ranger # -# This is a bash function for .bashrc to automatically change the directory to -# the last visited one after ranger quits. +# This is a shell function to automatically change the current working +# directory to the last visited one after ranger quits. # To undo the effect of this function, you can type "cd -" to return to the # original directory. diff --git a/examples/bash_subshell_notice.sh b/examples/bash_subshell_notice.sh index 4c9269c4..b64ca7fa 100644 --- a/examples/bash_subshell_notice.sh +++ b/examples/bash_subshell_notice.sh @@ -1,7 +1,9 @@ +#!/bin/sh + # Compatible with ranger 1.5.3 through 1.7.* # # Change the prompt when you open a shell from inside ranger # -# Add this line to your .bashrc for it to work. +# Add this line to your shell startup file (.bashrc, .zshrc etc) for it to work. [ -n "$RANGER_LEVEL" ] && PS1="$PS1"'(in ranger) ' -- cgit 1.4.1-2-gfad0 From 65721319e06789763798d0db1a7c24a08fee0bcd Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Sat, 2 Nov 2019 15:21:20 +0200 Subject: Renamed script files to not mention Bash --- examples/bash_automatic_cd.sh | 22 ---------------------- examples/bash_subshell_notice.sh | 9 --------- examples/shell_automatic_cd.sh | 22 ++++++++++++++++++++++ examples/shell_subshell_notice.sh | 9 +++++++++ 4 files changed, 31 insertions(+), 31 deletions(-) delete mode 100644 examples/bash_automatic_cd.sh delete mode 100644 examples/bash_subshell_notice.sh create mode 100644 examples/shell_automatic_cd.sh create mode 100644 examples/shell_subshell_notice.sh (limited to 'examples/bash_automatic_cd.sh') diff --git a/examples/bash_automatic_cd.sh b/examples/bash_automatic_cd.sh deleted file mode 100644 index 294f3aaa..00000000 --- a/examples/bash_automatic_cd.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -# Compatible with ranger 1.4.2 through 1.7.* -# -# Automatically change the current working directory after closing ranger -# -# This is a shell function to automatically change the current working -# directory to the last visited one after ranger quits. -# To undo the effect of this function, you can type "cd -" to return to the -# original directory. - -ranger_cd() { - temp_file="$(mktemp -t "ranger_cd.XXXXXXXXXX")" - ranger --choosedir="$temp_file" -- "${@:-$PWD}" - if chosen_dir="$(cat -- "$temp_file")" && [ -n "$chosen_dir" ] && [ "$chosen_dir" != "$PWD" ]; then - cd -- "$chosen_dir" - fi - rm -f -- "$temp_file" -} - -# This binds Ctrl-O to ranger-cd: -bind '"\C-o":"ranger-cd\C-m"' diff --git a/examples/bash_subshell_notice.sh b/examples/bash_subshell_notice.sh deleted file mode 100644 index b64ca7fa..00000000 --- a/examples/bash_subshell_notice.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -# Compatible with ranger 1.5.3 through 1.7.* -# -# Change the prompt when you open a shell from inside ranger -# -# Add this line to your shell startup file (.bashrc, .zshrc etc) for it to work. - -[ -n "$RANGER_LEVEL" ] && PS1="$PS1"'(in ranger) ' diff --git a/examples/shell_automatic_cd.sh b/examples/shell_automatic_cd.sh new file mode 100644 index 00000000..294f3aaa --- /dev/null +++ b/examples/shell_automatic_cd.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +# Compatible with ranger 1.4.2 through 1.7.* +# +# Automatically change the current working directory after closing ranger +# +# This is a shell function to automatically change the current working +# directory to the last visited one after ranger quits. +# To undo the effect of this function, you can type "cd -" to return to the +# original directory. + +ranger_cd() { + temp_file="$(mktemp -t "ranger_cd.XXXXXXXXXX")" + ranger --choosedir="$temp_file" -- "${@:-$PWD}" + if chosen_dir="$(cat -- "$temp_file")" && [ -n "$chosen_dir" ] && [ "$chosen_dir" != "$PWD" ]; then + cd -- "$chosen_dir" + fi + rm -f -- "$temp_file" +} + +# This binds Ctrl-O to ranger-cd: +bind '"\C-o":"ranger-cd\C-m"' diff --git a/examples/shell_subshell_notice.sh b/examples/shell_subshell_notice.sh new file mode 100644 index 00000000..b64ca7fa --- /dev/null +++ b/examples/shell_subshell_notice.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +# Compatible with ranger 1.5.3 through 1.7.* +# +# Change the prompt when you open a shell from inside ranger +# +# Add this line to your shell startup file (.bashrc, .zshrc etc) for it to work. + +[ -n "$RANGER_LEVEL" ] && PS1="$PS1"'(in ranger) ' -- cgit 1.4.1-2-gfad0