Browse Source

Add and use vimpager as default pager.

Emmanuel Bouthenot 14 years ago
parent
commit
2ebecf8c57
2 changed files with 94 additions and 3 deletions
  1. 87 0
      .vim/bin/vimpager
  2. 7 3
      .zsh.d/config.d/alias.zsh

+ 87 - 0
.vim/bin/vimpager

@@ -0,0 +1,87 @@
+#!/bin/sh
+
+# Script for using ViM as a PAGER.
+# Based on Bram's less.sh.
+# Version 1.4
+# git://github.com/rkitover/vimpager.git
+
+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 'let no_plugin_maps = 1' \
+    -c 'set scrolloff=999' \
+    -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\|doc2\)\|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\|doc2\)\>'; 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
+# Ivan S. Freitas <ivansichfreitas@gmail.com>

+ 7 - 3
.zsh.d/config.d/alias.zsh

@@ -17,10 +17,14 @@ fi
 #
 # Pager
 #
-if -exe most; then
+if -exe vim; then
+    export PAGER=~/.vim/bin/vimpager
+    alias less="$PAGER"
+    alias more="$PAGER"
+elif -exe most; then
     export PAGER=most
-    alias less='most'
-    alias more='most'
+    alias less="$PAGER"
+    alias more="$PAGER"
 elif -exe less; then
     export PAGER=less
 elif -exe more; then