workman.sh 854 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #! /bin/sh
  2. # Convert manual page troff stdin to formatted .txt stdout.
  3. # This file is in the public domain, so clarified as of
  4. # 2009-05-17 by Arthur David Olson.
  5. if (type nroff && type perl) >/dev/null 2>&1; then
  6. # Tell groff not to emit SGR escape sequences (ANSI color escapes).
  7. GROFF_NO_SGR=1
  8. export GROFF_NO_SGR
  9. echo ".am TH
  10. .hy 0
  11. .na
  12. ..
  13. .rm }H
  14. .rm }F" | nroff -man - ${1+"$@"} | perl -ne '
  15. binmode STDIN, '\'':encoding(utf8)'\'';
  16. binmode STDOUT, '\'':encoding(utf8)'\'';
  17. chomp;
  18. s/.\010//g;
  19. s/\s*$//;
  20. if (/^$/) {
  21. $sawblank = 1;
  22. next;
  23. } else {
  24. if ($sawblank && $didprint) {
  25. print "\n";
  26. $sawblank = 0;
  27. }
  28. print "$_\n";
  29. $didprint = 1;
  30. }
  31. '
  32. elif (type mandoc && type col) >/dev/null 2>&1; then
  33. mandoc -man -T ascii "$@" | col -bx
  34. else
  35. echo >&2 "$0: please install nroff and perl, or mandoc and col"
  36. exit 1
  37. fi