summaryrefslogtreecommitdiffstats
path: root/vimpager
diff options
context:
space:
mode:
authorRaghavendra D Prabhu <raghu.prabhu13@gmail.com>2011-03-13 00:24:47 +0530
committerRaghavendra D Prabhu <raghu.prabhu13@gmail.com>2011-03-13 00:24:47 +0530
commit5ec75ea891c9b44cdd2d7a3e0c29b4d08dff2b2a (patch)
treedeabb15393558ab3a1a629fc0782d8b0c3124c48 /vimpager
downloadScripts-5ec75ea891c9b44cdd2d7a3e0c29b4d08dff2b2a.tar.gz
Scripts-5ec75ea891c9b44cdd2d7a3e0c29b4d08dff2b2a.tar.bz2
Scripts-5ec75ea891c9b44cdd2d7a3e0c29b4d08dff2b2a.zip
Initial scripts update
Diffstat (limited to 'vimpager')
-rwxr-xr-xvimpager86
1 files changed, 86 insertions, 0 deletions
diff --git a/vimpager b/vimpager
new file mode 100755
index 0000000..5a5c85b
--- /dev/null
+++ b/vimpager
@@ -0,0 +1,86 @@
+#!/bin/sh
+
+# Script for using ViM as a PAGER.
+# Based on Bram's less.sh.
+# Version 1.3
+
+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
+elif uname -s | grep -iq sunos; then
+ solaris=1
+else
+ bsd=1
+fi
+
+less_vim() {
+ vim -R \
+ -c 'set nospell' \
+ -c 'let no_plugin_maps = 1' \
+ -c 'set scrolloff=5' \
+ -c 'runtime! macros/less.vim' \
+ -c 'set foldlevel=999' \
+ -c 'set mouse=h' \
+ -c 'set nonu' \
+ -c 'nmap <ESC>u :nohlsearch<cr>' \
+ "$@"
+}
+
+do_ps() {
+ if [ $solaris ]; then
+ ps -u `id -u` -o pid,comm=
+ elif [ $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
+# Koen Smits