summary refs log tree commit diff stats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/README2
-rw-r--r--examples/bash_automatic_cd.sh19
-rw-r--r--examples/bash_subshell_notice.sh5
-rwxr-xr-xexamples/rifle_sxiv.sh26
-rw-r--r--examples/vim_file_chooser.vim15
5 files changed, 67 insertions, 0 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/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh
new file mode 100755
index 00000000..efa935b2
--- /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 -L "$(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()<CR>