Skip to content

Instantly share code, notes, and snippets.

@AlexDenisov
Last active February 10, 2021 03:26
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexDenisov/4294335 to your computer and use it in GitHub Desktop.
Save AlexDenisov/4294335 to your computer and use it in GitHub Desktop.
This script creates PDF from man page and opens it within Preview.app. Only Mac OS X.

pman

Generates PDF from man page and opens it within Preview.app.

Install

curl -o /usr/local/bin/pman https://gist.githubusercontent.com/AlexDenisov/4294335/raw/9fe40c81f6fc94760e81040d2636d0e703fc676f/pman.pl
chmod +x /usr/local/bin/pman

Usage

pman 2 open
pman calloc
#!/usr/bin/perl
use strict;
use warnings;
my $cacheDir = $ENV{"HOME"} . "/.pdfman";
my $manFile = "$cacheDir/@ARGV.pdf";
my $tmpPsFile = "/tmp/@ARGV.ps";
unless (@ARGV) {
print "Usage: \n";
print " pman 2 open\n";
exit 1;
}
sub generateCache {
my $pageExists = system("man -t @_ > '$tmpPsFile' 2>/dev/null");
$" = " ";
if ($pageExists != 0) {
print "Could not find man page for '@_'\n";
exit 1;
}
print "Generating first time pdf for '@_'\n";
system("pstopdf '$tmpPsFile' -o '$manFile' /dev/null");
}
system("mkdir $cacheDir") unless -d $cacheDir;
generateCache(@ARGV) unless -e $manFile;
system("open -a /Applications/Preview.app '$manFile'");
@stanislaw
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment