summaryrefslogtreecommitdiffstats
path: root/vimpager
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@server-speed.net>2011-03-20 15:05:33 +0100
committerFlorian Pritz <bluewind@server-speed.net>2011-03-20 15:05:33 +0100
commit2b3616cbe01229996013bd517d162af190d688b9 (patch)
treec4e3fdc219e2a2a97430ffcbce8b57f9b7dc6bdb /vimpager
parent171a269f0ee4b33f199a1edaa26388aaf9dcdd33 (diff)
downloadbin-2b3616cbe01229996013bd517d162af190d688b9.tar.gz
bin-2b3616cbe01229996013bd517d162af190d688b9.tar.xz
update vimpager
Signed-off-by: Florian Pritz <bluewind@server-speed.net>
Diffstat (limited to 'vimpager')
-rwxr-xr-xvimpager110
1 files changed, 55 insertions, 55 deletions
diff --git a/vimpager b/vimpager
index 1388742..554c60f 100755
--- a/vimpager
+++ b/vimpager
@@ -2,74 +2,71 @@
# Script for using ViM as a PAGER.
# Based on Bram's less.sh.
-# Version 1.1
+# Version 1.4.3
+# 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
-else
- bsd=1
+# Just pass through if not on a tty
+if [ ! -t 1 ]; then
+ exec cat "$@"
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=a' \
- "$@"
-}
+case `uname -s` in
+ Cygwin) cygwin=1 ;;
+ Linux) linux=1 ;;
+ SunOS) solaris=1 ;;
+ *) bsd=1 ;;
+esac
-do_ps() {
- if [ $bsd ]; then
- ps -u `id -u` -o pid,comm=
- else
- ps fuxw
- 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>' \
+ "${@:--}"
}
-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
+awk_pstree() {
+ awk -v mypid=$1 '{
+ cmd[$1]=$3
+ ppid[$1]=$2
+ }
+ END {
+ while (mypid != 1 && cmd[mypid]) {
+ ptree=mypid " " cmd[mypid] "\n" ptree
+ mypid=ppid[mypid]
+ }
+ print ptree
+ }'
}
-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
+do_ptree() {
+ if [ $solaris ]; then
+ # Tested on Solaris 8 and 10
+ ptree $$
+ else
+ # Tested on Linux and OS X
+ ps awo pid=,ppid=,comm= | awk_pstree $$
+ 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; s/.//g' | less_vim -c 'set ft=man' -c "set nonumber" -; exit
- elif pproc $next_parent | grep -q 'py\(thon\|doc\)\>'; then
- cat $file | sed -e 's/\[[^m]*m//g; 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
+ptree="`do_ptree`"
+if echo "$ptree" | awk '$2 ~ /(^|\/)(man|perl(doc)?([0-9.]*)?|py(thon|doc|doc2))/ {t=1} END { exit 1-t }'; then
+ sed -e 's/\[[^m]*m//g' -e 's/.//g' "${@:--}" \
+ | less_vim -c 'set ft=man' -c "set nonumber" -
+ exit
fi
-cat $file | sed -e 's/\[[^m]*m//g; s/.//g' | less_vim -; exit
-#less_vim "$file"
+case "$@" in
+ *.gz) gunzip -c "${@:--}" | sed -e 's/\[[^m]*m//g' -e 's/.//g' | less_vim - ;;
+ *.Z) uncompress -c "${@:--}" | sed -e 's/\[[^m]*m//g' -e 's/.//g' | less_vim - ;;
+ *) sed -e 's/\[[^m]*m//g' -e 's/.//g' "${@:--}" | less_vim - ;;
+esac
+
# CONTRIBUTORS:
#
@@ -77,3 +74,6 @@ cat $file | sed -e 's/\[[^m]*m//g; s/.//g' | less_vim -; exit
# Antonio Ospite
# Jean-Marie Gaillourdet
# Perry Hargrave
+# Koen Smits
+# Ivan S. Freitas <ivansichfreitas@gmail.com>
+# Wout Mertens (Solaris compatibility, less processes)