Commits

Anonymous committed 16010dc

add vimpager

Comments (0)

Files changed (1)

+#!/bin/sh
+
+# Script for using ViM as a PAGER.
+# Based on Bram's less.sh.
+# Perlified by Magnus Woldrich.
+
+# If perldoc is called, we use the specialized perldoc.vim syntax file,
+# included in this distribution.
+#
+# Set wanted options in ~/.vimpagerrc
+
+file="$@"
+if [ -z "$file" ]; then file="-"; fi
+
+less_vim() {
+  /usr/bin/vim -R -X \
+    "$@"
+}
+
+do_ps() {
+  ps fuxw
+}
+
+pproc() {
+  ps -p $1 -o comm=
+}
+
+ppid() {
+  ps -p $1 -o ppid=
+}
+
+# Check if called from man, perldoc or pydoc
+if do_ps | grep -q 'mail\|\man\|godoc\|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 'perl\(doc\)\?\([0-9.]*\)\?\>'; then
+      cat $file | sed -e 's/.//g' | less_vim -c 'set ft=perldoc' -; exit
+    elif pproc $next_parent | grep -q 'godoc'; then
+      cat $file | sed -e 's/.//g' | less_vim -c 'set ft=go' -; exit
+    elif pproc $next_parent | grep -q 'mail'; then
+      cat $file | sed -e 's/.//g' | less_vim -c 'set ft=rmail' -; exit
+    fi
+    proc=$next_parent
+  done
+else
+  echo "Could not spawn vimpager."
+fi
+
+less_vim "$file"