about summary refs log tree commit diff
path: root/Functions/Misc/mere
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>2000-12-15 14:42:22 +0000
committerTanaka Akira <akr@users.sourceforge.net>2000-12-15 14:42:22 +0000
commit35ac156d869f6e99131c2dff6e9e7c9f1123c5e4 (patch)
tree11c49f19a81ccd804f9a91da4de2438ea532f05c /Functions/Misc/mere
parent81185fe668de1a53f4632b3d185f41c11388501c (diff)
downloadzsh-35ac156d869f6e99131c2dff6e9e7c9f1123c5e4.tar.gz
zsh-35ac156d869f6e99131c2dff6e9e7c9f1123c5e4.tar.xz
zsh-35ac156d869f6e99131c2dff6e9e7c9f1123c5e4.zip
* 13281: Functions/Misc/mere: new implementation.
Completion/User/_mere: new completion function for mere.
Diffstat (limited to 'Functions/Misc/mere')
-rw-r--r--Functions/Misc/mere86
1 files changed, 83 insertions, 3 deletions
diff --git a/Functions/Misc/mere b/Functions/Misc/mere
index cf8d8ad14..496c67061 100644
--- a/Functions/Misc/mere
+++ b/Functions/Misc/mere
@@ -1,3 +1,83 @@
-#! /bin/sh
-# read a man page in the current directory
-nroff -man -Tman $1 | less -s
+# read a man page
+
+setopt localoptions extendedglob
+
+local manual="$1" col=col terminal=man magic line
+
+# /usr/bin/col on SunOS 4 doesn't support -x.
+if [[ -x /usr/5bin/col ]]; then
+  col=/usr/5bin/col;
+fi
+
+# SunOS 5 has no `man' terminal.
+if [[ -d /usr/share/lib/nterm &&
+    ! -e /usr/share/lib/nterm/tab.$terminal ]]; then
+  terminal=lp;
+fi
+
+# HP-UX has no `man' terminal.
+if [[ -d /usr/share/lib/term &&
+    ! -e /usr/share/lib/term/tab$terminal ]]; then
+  terminal=lp;
+fi
+
+# Unixware has no `man' terminal.
+if [[ -d /usr/ucblib/doctools/nterm &&
+    ! -e /usr/ucblib/doctools/nterm/tab.$terminal ]]; then
+  terminal=lp;
+fi
+
+# Solaris has SGML manuals.
+if [[ -f /usr/lib/sgml/sgml2roff ]] && 
+   [[ "$(read -er < $manual)" = "<!DOCTYPE"* ]]; then
+  /usr/lib/sgml/sgml2roff $manual | {
+    read -r line
+    if [[ $line = ".so "* ]]; then
+      # There is no cascading .so directive.
+      # On Solaris 7, at least.
+      /usr/lib/sgml/sgml2roff ${line#.so }
+    else
+      print -lr - "$line"
+      cat
+    fi
+  }
+else
+  read -u0 -k 2 magic < $manual
+  case $magic in
+  $'\037\235') zcat $manual;;
+  $'\037\213') gzip -dc $manual;;
+  *) cat $manual;;
+  esac
+fi | (
+  # cd is required to work soelim called by nroff.
+  case $manual in
+  */man/man*/*) cd ${manual:h:h};;
+  */man/sman*/*) cd ${manual:h:h};;
+  esac
+  read -r line
+  # The first line beginning with '\" shows preprocessors.
+  # Unknown preprocessors is ignored.
+  if [[ $line = "'\\\" "* ]]; then
+    typeset -A filter
+    filter=(
+      e neqn
+      g grap
+      p pic
+      r refer
+      t tbl
+      v vgrind
+    )
+    eval ${(j:|:)${${(s::)line#\'\\\" }//(#m)?/$filter[$MATCH]}}
+  elif [[ $line = "'\\\"! "* ]]; then
+    typeset -A filter
+    filter=(
+      eqn neqn
+    )
+    eval ${(j:|:)${${${${(s:|:)line#\'\\\"! }# ##}% ##}//(#m)*/$filter[$MATCH]}}
+  else
+    print -lr - "$line"
+    cat
+  fi |
+  nroff -T$terminal -man | $col -x
+) |
+${MANPAGER:-${PAGER:-more}} -s