summaryrefslogtreecommitdiffstats
path: root/vimpager
diff options
context:
space:
mode:
authorFlorian Pritz <f-p@gmx.at>2009-06-05 17:27:29 +0200
committerFlorian Pritz <f-p@gmx.at>2009-06-05 17:27:29 +0200
commit11eac06a26b84c8b7771dd98c7026f8b8c4639f5 (patch)
treeaa0c716f30162cb180b02b7ca1072a7628c29eb7 /vimpager
parent48cc896fa665bc083ae6807726c20bcc2c3f6167 (diff)
downloadbin-11eac06a26b84c8b7771dd98c7026f8b8c4639f5.tar.gz
bin-11eac06a26b84c8b7771dd98c7026f8b8c4639f5.tar.xz
add vimpager
Diffstat (limited to 'vimpager')
-rwxr-xr-xvimpager78
1 files changed, 78 insertions, 0 deletions
diff --git a/vimpager b/vimpager
new file mode 100755
index 0000000..ab38ae6
--- /dev/null
+++ b/vimpager
@@ -0,0 +1,78 @@
+#!/bin/sh
+
+# Script for using ViM as a PAGER.
+# Based on Bram's less.sh.
+# Version 1.1
+
+file="$@"
+if [ -z "$file" ]; then file="-"; fi
+
+if uname -s | grep -iq cygwin; then
+ cygwin=1
+elif uname -s | grep -iq Linux; then
+ linux=1
+else
+ bsd=1
+fi
+
+less_vim() {
+ vim -R \
+ -c 'let no_plugin_maps = 1' \
+ -c 'set scrolloff=999' \
+ -c 'runtime! macros/less.vim' \
+ -c 'set foldlevel=999' \
+ -c 'set mouse=h' \
+ "$@"
+}
+
+do_ps() {
+ if [ $bsd ]; then
+ ps -u `id -u` -o pid,comm=
+ else
+ ps fuxw
+ fi
+}
+
+pproc() {
+ if [ $linux ]; then
+ ps -p $1 -o comm=
+ elif [ $cygwin ]; then
+ ps -p $1 | sed -e 's/^I/ /' | grep -v PID
+ else
+ ps -p $1 -o comm= | grep -v PID
+ fi
+}
+
+ppid() {
+ if [ $linux ]; then
+ ps -p $1 -o ppid=
+ elif [ $cygwin ]; then
+ ps -p $1 | sed -e 's/^I/ /' | grep -v PID | awk '{print $2}'
+ else
+ ps -p $1 -o ppid= | grep -v PID
+ fi
+}
+
+# Check if called from man, perldoc or pydoc
+if do_ps | grep -q '\(py\(thon\|doc\)\|man\|perl\(doc\)\?\([0-9.]*\)\?\)\>'; then
+ proc=$$
+ while next_parent=`ppid $proc` && [ $next_parent != 1 ]; do
+ if pproc $next_parent | grep -q 'man\>'; then
+ cat $file | sed -e 's/\[[^m]*m//g' | sed -e 's/.//g' | less_vim -c 'set ft=man' -; exit
+ elif pproc $next_parent | grep -q 'py\(thon\|doc\)\>'; then
+ cat $file | sed -e 's/\[[^m]*m//g' | sed -e 's/.//g' | less_vim -c 'set ft=man' -; exit
+ elif pproc $next_parent | grep -q 'perl\(doc\)\?\([0-9.]*\)\?\>'; then
+ cat $file | sed -e 's/.//g' | less_vim -c 'set ft=man' -; exit
+ fi
+ proc=$next_parent
+ done
+fi
+
+less_vim "$file"
+
+# CONTRIBUTORS:
+#
+# Rafael Kitover
+# Antonio Ospite
+# Jean-Marie Gaillourdet
+# Perry Hargrave