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 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') 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') 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') 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') 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') 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') 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') 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') 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 From aebcf5bc82fbb1f478d1ec62a0701774bcdd6b1c Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Wed, 6 Nov 2019 21:47:03 +0200 Subject: Removed shebangs --- examples/shell_automatic_cd.sh | 2 -- examples/shell_subshell_notice.sh | 2 -- 2 files changed, 4 deletions(-) (limited to 'examples') diff --git a/examples/shell_automatic_cd.sh b/examples/shell_automatic_cd.sh index 294f3aaa..952a0564 100644 --- a/examples/shell_automatic_cd.sh +++ b/examples/shell_automatic_cd.sh @@ -1,5 +1,3 @@ -#!/bin/sh - # Compatible with ranger 1.4.2 through 1.7.* # # Automatically change the current working directory after closing ranger diff --git a/examples/shell_subshell_notice.sh b/examples/shell_subshell_notice.sh index b64ca7fa..a79712ee 100644 --- a/examples/shell_subshell_notice.sh +++ b/examples/shell_subshell_notice.sh @@ -1,5 +1,3 @@ -#!/bin/sh - # Compatible with ranger 1.5.3 through 1.7.* # # Change the prompt when you open a shell from inside ranger -- cgit 1.4.1-2-gfad0 From 918da47421cd4f162d2ecce4f0eeef3bc3e7a3ab Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Wed, 6 Nov 2019 21:47:30 +0200 Subject: Updated comments about compatibility with ranger versions --- examples/shell_automatic_cd.sh | 2 +- examples/shell_subshell_notice.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/shell_automatic_cd.sh b/examples/shell_automatic_cd.sh index 952a0564..136c1e26 100644 --- a/examples/shell_automatic_cd.sh +++ b/examples/shell_automatic_cd.sh @@ -1,4 +1,4 @@ -# Compatible with ranger 1.4.2 through 1.7.* +# Compatible with ranger 1.4.2 through 1.9.* # # Automatically change the current working directory after closing ranger # diff --git a/examples/shell_subshell_notice.sh b/examples/shell_subshell_notice.sh index a79712ee..a3c39dc0 100644 --- a/examples/shell_subshell_notice.sh +++ b/examples/shell_subshell_notice.sh @@ -1,4 +1,4 @@ -# Compatible with ranger 1.5.3 through 1.7.* +# Compatible with ranger 1.5.3 through 1.9.* # # Change the prompt when you open a shell from inside ranger # -- cgit 1.4.1-2-gfad0 From f691e05a8f5e527c1beff8e112def4a40693ad7b Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Wed, 6 Nov 2019 21:59:27 +0200 Subject: Added mention about sourcing examples/shell_automatic_cd.sh from shell config --- examples/shell_automatic_cd.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/shell_automatic_cd.sh b/examples/shell_automatic_cd.sh index 136c1e26..c4d79cb9 100644 --- a/examples/shell_automatic_cd.sh +++ b/examples/shell_automatic_cd.sh @@ -3,7 +3,8 @@ # 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. +# directory to the last visited one after ranger quits. Either put it into your +# .zshrc/.bashrc/etc or source this file from your shell configuration. # To undo the effect of this function, you can type "cd -" to return to the # original directory. -- cgit 1.4.1-2-gfad0 From 77154c4e07d2ccb2288361e303b2484523947189 Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Wed, 6 Nov 2019 22:30:20 +0200 Subject: Added a notice about sourcing examples/shell_subshell_notice.sh as well --- examples/shell_subshell_notice.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/shell_subshell_notice.sh b/examples/shell_subshell_notice.sh index a3c39dc0..1db88bfc 100644 --- a/examples/shell_subshell_notice.sh +++ b/examples/shell_subshell_notice.sh @@ -2,6 +2,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. +# Source this file from 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 5dc0d60a56679da5f98cfc8a03273ccafa6d016a Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Wed, 6 Nov 2019 22:38:54 +0200 Subject: Added shellcheck directives for specifying shell --- examples/shell_automatic_cd.sh | 2 ++ examples/shell_subshell_notice.sh | 2 ++ 2 files changed, 4 insertions(+) (limited to 'examples') diff --git a/examples/shell_automatic_cd.sh b/examples/shell_automatic_cd.sh index c4d79cb9..391946c7 100644 --- a/examples/shell_automatic_cd.sh +++ b/examples/shell_automatic_cd.sh @@ -1,3 +1,5 @@ +# shellcheck shell=sh + # Compatible with ranger 1.4.2 through 1.9.* # # Automatically change the current working directory after closing ranger diff --git a/examples/shell_subshell_notice.sh b/examples/shell_subshell_notice.sh index 1db88bfc..0d8d2431 100644 --- a/examples/shell_subshell_notice.sh +++ b/examples/shell_subshell_notice.sh @@ -1,3 +1,5 @@ +# shellcheck shell=sh + # Compatible with ranger 1.5.3 through 1.9.* # # Change the prompt when you open a shell from inside ranger -- cgit 1.4.1-2-gfad0