diff options
-rw-r--r-- | examples/README | 2 | ||||
-rw-r--r-- | examples/bash_automatic_cd.sh | 19 | ||||
-rw-r--r-- | examples/bash_subshell_notice.sh | 5 | ||||
-rwxr-xr-x | examples/rifle_sxiv.sh (renamed from doc/sxivall.sh) | 9 | ||||
-rw-r--r-- | examples/vim_file_chooser.vim | 15 |
5 files changed, 46 insertions, 4 deletions
diff --git a/examples/README b/examples/README new file mode 100644 index 00000000..60f29ac6 --- /dev/null +++ b/examples/README @@ -0,0 +1,2 @@ +Thes files in this directory contain applications or extensions of ranger which +are put here for your inspiration and as references. diff --git a/examples/bash_automatic_cd.sh b/examples/bash_automatic_cd.sh new file mode 100644 index 00000000..a63280d1 --- /dev/null +++ b/examples/bash_automatic_cd.sh @@ -0,0 +1,19 @@ +# 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='/tmp/chosendir' + /usr/bin/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 new file mode 100644 index 00000000..b6b03d74 --- /dev/null +++ b/examples/bash_subshell_notice.sh @@ -0,0 +1,5 @@ +# 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/doc/sxivall.sh b/examples/rifle_sxiv.sh index 228114ce..5eb52fc0 100755 --- a/doc/sxivall.sh +++ b/examples/rifle_sxiv.sh @@ -7,19 +7,20 @@ # sxiv takes no file name arguments for the first image, just the number. # Copy this file somewhere into your $PATH and add this at the top of rifle.conf: # -# mime ^image, has sxiv, X, flag f = sxivall.sh -- "$@" +# mime ^image, has sxiv, X, flag f = path/to/this/script -- "$@" # [ "$1" == '--' ] && shift target="$(realpath -s "$1")" function listfiles { - find "$(dirname "$target")" -maxdepth 1 -type f -iregex '.*\(jpe?g\|bmp\|png\|gif\)$' -print0 | sort -z + find "$(dirname "$target")" -maxdepth 1 -type f -iregex \ + '.*\(jpe?g\|bmp\|png\|gif\)$' -print0 | sort -z } count="$(listfiles | grep -m 1 -Zznx "$target" | cut -d: -f1)" if [ -n "$count" ]; then - listfiles | xargs -0 sxiv -n "$count" -- + listfiles | xargs -0 sxiv -n "$count" -- else - sxiv -- "$@" # fallback + sxiv -- "$@" # fallback fi diff --git a/examples/vim_file_chooser.vim b/examples/vim_file_chooser.vim new file mode 100644 index 00000000..a44ab2b7 --- /dev/null +++ b/examples/vim_file_chooser.vim @@ -0,0 +1,15 @@ +" Add ranger as a file chooser in vim +" +" If you add this function and the key binding to the .vimrc, ranger can be +" started using the keybinding ",r". Once you select a file by pressing +" enter, ranger will quit again and vim will open the selected file. + +fun! RangerChooser() + exec "silent !ranger --choosefile=/tmp/chosenfile " . expand("%:p:h") + if filereadable('/tmp/chosenfile') + exec 'edit ' . system('cat /tmp/chosenfile') + call system('rm /tmp/chosenfile') + endif + redraw! +endfun +map ,r :call RangerChooser()<CR> |