#!/bin/sh # Set this as your pager via the PAGER environment variable. Works great with # man and every other app that has used it so far. # Uses my pager.vim macro which just tweaks the vim settings to behave in a # more pager like way. Get the pager.vim macro and put it in ~/.vim/macros/. # # For man pages I also have a man_title.vim a filetype plugin which places the # man page's topic in the x-terminal's titlebar. Just put it in # ~/.vim/ftplugin/. # # The pager.vim macro and man_title.vim plugin should be available on my site # (probably right next to where you got this) at # . If not there look around for a vim area, # I'm thinking about created one. # 0 - stdin # 1 - stdout # 2 - stderr usage () { echo "usage: $cmd [options] [FILE]" echo "-g use gui" echo "-m file is man page" } vim="vim" man= while getopts gm arg; do case $arg in g) vim="gvim"; shift;; m) man="true"; shift;; h) usage;; esac done # run as gvim? [ `basename $0` = "gpager" ] && vim="gvim" view="${vim} -R -i $TMPDIR/.viminfo" if [ -t 0 ]; then # stdin is open (file on command line) if [ -n "$man" ]; then # perldoc calls as man viewer w/ tmpfile # don't alter the original tmp=`mktemp` cat "$1" | col -bx > $tmp $view -c 'runtime macros/pager.vim' -c 'set ft=man' "$tmp" rm $tmp else exec $view -c 'runtime macros/pager.vim' "$@" # --cmd "au BufNewFile * cq" "$@" fi elif [ -t 1 ]; then # stdin closed (0) but stdout open # piped input (eg. man viewer) if [ -n "$man" ]; then # -m indicates man page exec col -bx | $view -c 'runtime macros/pager.vim' -c 'set ft=man' - else exec $view -c 'runtime macros/pager.vim' - fi else # man w/ piped output exec cat fi # stuff I was testing. # need to get this in a vcs so I delete crap like this... # # view --cmd 'let no_plugin_maps = 1' \ # -c 'set nomod nolist ignorecase wrapscan' \ # col -bx | view --cmd 'let no_plugin_maps = 1' \ # -c 'set ft=man nomod nolist ignorecase wrapscan' \ # -c "set ls=2" -c 'noremap ' -c 'noremap ' -