From 796074b541aaca459c594fe517c11d275778eef6 Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 6 Aug 2012 06:32:04 +0200 Subject: added the examples from the man page to the examples directory I guess a whole directory for examples scales better than having them in the man page. --- doc/sxivall.sh | 25 ------------------------- examples/README | 2 ++ examples/bash_automatic_cd.sh | 19 +++++++++++++++++++ examples/bash_subshell_notice.sh | 5 +++++ examples/rifle_sxiv.sh | 26 ++++++++++++++++++++++++++ examples/vim_file_chooser.vim | 15 +++++++++++++++ 6 files changed, 67 insertions(+), 25 deletions(-) delete mode 100755 doc/sxivall.sh create mode 100644 examples/README create mode 100644 examples/bash_automatic_cd.sh create mode 100644 examples/bash_subshell_notice.sh create mode 100755 examples/rifle_sxiv.sh create mode 100644 examples/vim_file_chooser.vim diff --git a/doc/sxivall.sh b/doc/sxivall.sh deleted file mode 100755 index 228114ce..00000000 --- a/doc/sxivall.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash -# -# This script searches image files in a directory, opens them all with sxiv -# and sets the first argument to the first image displayed by sxiv. -# -# This is supposed to be used in rifle.conf as a workaround for the fact that -# 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 -- "$@" -# - -[ "$1" == '--' ] && shift -target="$(realpath -s "$1")" -function listfiles { - 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" -- -else - sxiv -- "$@" # fallback -fi 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/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh new file mode 100755 index 00000000..5eb52fc0 --- /dev/null +++ b/examples/rifle_sxiv.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# +# This script searches image files in a directory, opens them all with sxiv +# and sets the first argument to the first image displayed by sxiv. +# +# This is supposed to be used in rifle.conf as a workaround for the fact that +# 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 = 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 +} + +count="$(listfiles | grep -m 1 -Zznx "$target" | cut -d: -f1)" + +if [ -n "$count" ]; then + listfiles | xargs -0 sxiv -n "$count" -- +else + 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() -- cgit 1.4.1-2-gfad0 ='#n47'>47 48 49