diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/bash_automatic_cd.sh | 21 | ||||
-rw-r--r-- | examples/bash_subshell_notice.sh | 7 | ||||
-rw-r--r-- | examples/shell_automatic_cd.sh | 23 | ||||
-rw-r--r-- | examples/shell_subshell_notice.sh | 10 |
4 files changed, 33 insertions, 28 deletions
diff --git a/examples/bash_automatic_cd.sh b/examples/bash_automatic_cd.sh deleted file mode 100644 index 04b58e24..00000000 --- a/examples/bash_automatic_cd.sh +++ /dev/null @@ -1,21 +0,0 @@ -# Compatible with ranger 1.4.2 through 1.7.* -# -# Automatically change the directory in bash after closing ranger -# -# This is a bash function for .bashrc to automatically change the 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. - -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")" - fi - rm -f -- "$tempfile" -} - -# 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 4c9269c4..00000000 --- a/examples/bash_subshell_notice.sh +++ /dev/null @@ -1,7 +0,0 @@ -# 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. - -[ -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..391946c7 --- /dev/null +++ b/examples/shell_automatic_cd.sh @@ -0,0 +1,23 @@ +# shellcheck shell=sh + +# Compatible with ranger 1.4.2 through 1.9.* +# +# 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. 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. + +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..0d8d2431 --- /dev/null +++ b/examples/shell_subshell_notice.sh @@ -0,0 +1,10 @@ +# shellcheck shell=sh + +# Compatible with ranger 1.5.3 through 1.9.* +# +# Change the prompt when you open a shell from inside ranger +# +# Source this file from your shell startup file (.bashrc, .zshrc etc) for it to +# work. + +[ -n "$RANGER_LEVEL" ] && PS1="$PS1"'(in ranger) ' |