Script for updating cached PDF man-pages - Unix

This is a discussion on Script for updating cached PDF man-pages - Unix ; I use a script (below) that converts man-pages to PDF and caches them (and opens them on Mac OS X using 'open'), except that if the cached PDF page already exists, it uses that one instead of converting one. The ...

+ Reply to Thread
Results 1 to 18 of 18

Thread: Script for updating cached PDF man-pages

  1. Script for updating cached PDF man-pages

    I use a script (below) that converts man-pages to PDF and caches them (and
    opens them on Mac OS X using 'open'), except that if the cached PDF page
    already exists, it uses that one instead of converting one.

    The problem is if the manpage is updated and already cached. Then I want
    the script to create a new PDF copy, instead of using the already cached.
    How might this be done?

    #!/bin/sh
    # manpdf -- open man pages in default PDF viewer (presumably Preview)
    MANDIR=${HOME}/Library/Caches/Manpages
    mkdir -p ${MANDIR}
    for MAN
    do
    PDFMAN=${MANDIR}/${MAN}.pdf
    [ -f ${PDFMAN} ] || (man -t ${MAN} | pstopdf -i -o ${PDFMAN})
    open ${PDFMAN}
    done

    --
    Hans Aberg

  2. Re: Script for updating cached PDF man-pages

    Begin
    On 2007-03-31, Hans Aberg wrote:
    > The problem is if the manpage is updated and already cached. Then I want
    > the script to create a new PDF copy, instead of using the already cached.
    > How might this be done?


    You could compare timestamps. The traditional tool that specialized
    in that sort of work is make.


    --
    j p d (at) d s b (dot) t u d e l f t (dot) n l .
    This message was originally posted on Usenet in plain text.
    Any other representation, additions, or changes do not have my
    consent and may be a violation of international copyright law.

  3. Re: Script for updating cached PDF man-pages

    In article <5776g1F2bqsodU1@mid.individual.net>, jpd
    wrote:

    > > The problem is if the manpage is updated and already cached. Then I want
    > > the script to create a new PDF copy, instead of using the already cached.
    > > How might this be done?

    >
    > You could compare timestamps. The traditional tool that specialized
    > in that sort of work is make.


    It is a good idea to use 'make', but one can also use shell '-nt'. Perhaps
    this is as simple it can get.

    --
    Hans Aberg

  4. Re: Script for updating cached PDF man-pages

    2007-03-31, 18:13(+00), Hans Aberg:
    > In article <5776g1F2bqsodU1@mid.individual.net>, jpd
    > wrote:
    >
    >> > The problem is if the manpage is updated and already cached. Then I want
    >> > the script to create a new PDF copy, instead of using the already cached.
    >> > How might this be done?

    >>
    >> You could compare timestamps. The traditional tool that specialized
    >> in that sort of work is make.

    >
    > It is a good idea to use 'make', but one can also use shell '-nt'. Perhaps
    > this is as simple it can get.


    -nt is not standard though. The POSIX equivalent to some test
    implementation's "-nt" is "find -newer".

    Also note that man is organised in sections. There can be a man
    page of a given name per section of the manual, and there can
    even be more than one per section (in different components of
    $MANPATH), so the script must let the user specify the section
    and the cache file can't only be named after the name of the man
    page.

    --
    Stéphane

  5. Re: Script for updating cached PDF man-pages

    In article , Stephane
    CHAZELAS wrote:

    > >> > The problem is if the manpage is updated and already cached. Then I want
    > >> > the script to create a new PDF copy, instead of using the already cached.
    > >> > How might this be done?
    > >>
    > >> You could compare timestamps. The traditional tool that specialized
    > >> in that sort of work is make.

    > >
    > > It is a good idea to use 'make', but one can also use shell '-nt'. Perhaps
    > > this is as simple it can get.

    >
    > -nt is not standard though. The POSIX equivalent to some test
    > implementation's "-nt" is "find -newer".


    It depends on the shell, and the script needs to be indicated.

    > Also note that man is organised in sections. There can be a man
    > page of a given name per section of the manual, and there can
    > even be more than one per section (in different components of
    > $MANPATH), so the script must let the user specify the section
    > and the cache file can't only be named after the name of the man
    > page.


    Yeah. Good point. This script just converts the first choice found. Nor
    does it handle various*arguments that can be given to man. Room for
    improvements. Below is the new version. Best would perhaps be to tweak
    'man' with a new option that pipes 'man -t' to a PD to PDF conversion
    program, and somehow cashes the stuff in the process.

    I am not sure what #!/bin/sh, the Bourne shell or bash ('man sh' gives
    'man bash', though). It works. Perhaps use '#!/bin/ksh' to be sure.

    #!/bin/sh
    # manpdf -- open man pages in default PDF viewer (presumably Preview)
    MANDIR=${HOME}/Library/Caches/Manpages
    /bin/mkdir -p ${MANDIR}
    for MAN
    do
    PDFMAN=${MANDIR}/${MAN}.pdf
    LOCMAN=$(man -w ${MAN})
    [ ${LOCMAN} -nt ${PDFMAN} ] && (man -t ${MAN} | pstopdf -i -o ${PDFMAN})
    open ${PDFMAN}
    done

    --
    Hans Aberg

  6. Re: Script for updating cached PDF man-pages

    2007-04-01, 12:25(+00), Hans Aberg:
    > In article , Stephane
    > CHAZELAS wrote:
    >
    >> >> > The problem is if the manpage is updated and already cached. Then I want
    >> >> > the script to create a new PDF copy, instead of using the already cached.
    >> >> > How might this be done?
    >> >>
    >> >> You could compare timestamps. The traditional tool that specialized
    >> >> in that sort of work is make.
    >> >
    >> > It is a good idea to use 'make', but one can also use shell '-nt'. Perhaps
    >> > this is as simple it can get.

    >>
    >> -nt is not standard though. The POSIX equivalent to some test
    >> implementation's "-nt" is "find -newer".

    >
    > It depends on the shell, and the script needs to be indicated.


    I mentionned "standard".

    Just as typeof() is not standard C, [ -nt ] is not standard
    sh. So it's not guaranteed to work with any standard compliant
    sh.

    find file1 -prune -newer file2 -exec ... \;

    is guaranteed to work with any standard find.

    [...]
    > #!/bin/sh


    Note that the standard sh is not necessarily in /bin. On some
    systems, /bin/sh is a Bourne shell (an old sh implementation
    from the time when there wasn't a specification for sh yet).

    > # manpdf -- open man pages in default PDF viewer (presumably Preview)
    > MANDIR=${HOME}/Library/Caches/Manpages
    > /bin/mkdir -p ${MANDIR}


    Leaving a variable expansion unquoted has a very special meaning
    to the shell, see a recent (and recurrent) discussion in
    comp.unix.shell

    What if mkdir fails to create a directory. You should always
    verify the return status of commands. Here:

    progname=$0
    die() {
    printf '%s: %s\n' >&2 "$progname" "$1"
    exit 1
    }

    mkdir -p -- "$MANDIR" 2> /dev/null
    [ -d "$MANDIR" ] || die "can't create cache dir"

    for instance.

    > for MAN
    > do
    > PDFMAN=${MANDIR}/${MAN}.pdf
    > LOCMAN=$(man -w ${MAN})
    > [ ${LOCMAN} -nt ${PDFMAN} ] && (man -t ${MAN} | pstopdf -i -o ${PDFMAN})


    You don't need a subshell above.

    > open ${PDFMAN}
    > done



    --
    Stéphane

  7. Re: Script for updating cached PDF man-pages

    In article , Stephane
    CHAZELAS wrote:

    > >> -nt is not standard though. The POSIX equivalent to some test
    > >> implementation's "-nt" is "find -newer".

    > >
    > > It depends on the shell, and the script needs to be indicated.

    >
    > I mentionned "standard".
    >
    > Just as typeof() is not standard C, [ -nt ] is not standard
    > sh. So it's not guaranteed to work with any standard compliant
    > sh.


    It is listed on the man pages of bash and ksh, though.

    > [...]
    > > #!/bin/sh

    >
    > Note that the standard sh is not necessarily in /bin. On some
    > systems, /bin/sh is a Bourne shell (an old sh implementation
    > from the time when there wasn't a specification for sh yet).


    Mac OS X has a FreeBSD in the bottom. I just try to write script for this
    platform; others will have to adapt for theirs. :-)

    > > # manpdf -- open man pages in default PDF viewer (presumably Preview)
    > > MANDIR=${HOME}/Library/Caches/Manpages
    > > /bin/mkdir -p ${MANDIR}

    >
    > Leaving a variable expansion unquoted has a very special meaning
    > to the shell, see a recent (and recurrent) discussion in
    > comp.unix.shell


    I am not what you are hinting at here. There is no attempt at capturing
    filenames with spaces in it, if that is what you have in your mind.

    > What if mkdir fails to create a directory. You should always
    > verify the return status of commands. Here:
    >
    > progname=$0
    > die() {
    > printf '%s: %s\n' >&2 "$progname" "$1"
    > exit 1
    > }
    >
    > mkdir -p -- "$MANDIR" 2> /dev/null
    > [ -d "$MANDIR" ] || die "can't create cache dir"
    >
    > for instance.


    It is good to have checks, though as written, I think 'mkdir -p' cannot
    fail, unless the disk is to so full nothing can be wrtten on it. :-)

    > > for MAN
    > > do
    > > PDFMAN=${MANDIR}/${MAN}.pdf
    > > LOCMAN=$(man -w ${MAN})
    > > [ ${LOCMAN} -nt ${PDFMAN} ] && (man -t ${MAN} | pstopdf -i -o ${PDFMAN})

    >
    > You don't need a subshell above.


    Where is it created?

    --
    Hans Aberg

  8. Re: Script for updating cached PDF man-pages

    Begin
    On 2007-04-01, Hans Aberg wrote:
    > Mac OS X has a FreeBSD in the bottom.


    No, it hasn't. It borrows quite a lot from FreeBSD, but that doesn't
    mean you can equate one with the other, any more than you can equate
    FreeBSD with NetBSD or OpenBSD. In fact, in quite a few ways darwin is
    very different from the other *BSDs. At the very least different enough
    to make your statement inaccurate in the general case.


    --
    j p d (at) d s b (dot) t u d e l f t (dot) n l .
    This message was originally posted on Usenet in plain text.
    Any other representation, additions, or changes do not have my
    consent and may be a violation of international copyright law.

  9. Re: Script for updating cached PDF man-pages

    In article , Stephane
    CHAZELAS wrote:

    > > # manpdf -- open man pages in default PDF viewer (presumably Preview)
    > > MANDIR=${HOME}/Library/Caches/Manpages
    > > /bin/mkdir -p ${MANDIR}

    >
    > Leaving a variable expansion unquoted has a very special meaning
    > to the shell, see a recent (and recurrent) discussion in
    > comp.unix.shell


    In view of the file name generation.

    --
    Hans Aberg

  10. Re: Script for updating cached PDF man-pages

    In article <57ai3hF2cb6btU1@mid.individual.net>, jpd
    wrote:

    > > Mac OS X has a FreeBSD in the bottom.

    >
    > No, it hasn't. It borrows quite a lot from FreeBSD, but that doesn't
    > mean you can equate one with the other, any more than you can equate
    > FreeBSD with NetBSD or OpenBSD. In fact, in quite a few ways darwin is
    > very different from the other *BSDs. At the very least different enough
    > to make your statement inaccurate in the general case.


    Well, the Mac OS X version has Mach in the bottom, whereas FreeBSD has its
    own kernel, and the latter was written for Intel chips, whereas the
    version I am running is for PPC chips. So there are some differences
    clearly. What do you have in your mind?

    --
    Hans Aberg

  11. Re: Script for updating cached PDF man-pages

    Begin
    On 2007-04-01, Hans Aberg wrote:
    > In article <57ai3hF2cb6btU1@mid.individual.net>, jpd
    > wrote:
    >> > Mac OS X has a FreeBSD in the bottom.

    >>
    >> No, it hasn't. It borrows quite a lot from FreeBSD, but that doesn't
    >> mean you can equate one with the other, any more than you can equate
    >> FreeBSD with NetBSD or OpenBSD. In fact, in quite a few ways darwin is
    >> very different from the other *BSDs. At the very least different enough
    >> to make your statement inaccurate in the general case.

    >
    > Well, the Mac OS X version has Mach in the bottom, whereas FreeBSD has its
    > own kernel, and the latter was written for Intel chips, whereas the
    > version I am running is for PPC chips. So there are some differences
    > clearly. What do you have in your mind?


    Exactly that. Your statement is inaccurate and misleading.

    The differences go much further. If you would care to know the details,
    apple provides a lot of documentation on developer.apple.com. It does
    not, however, claim that darwin ``is a'' FreeBSD, merely that it is
    ``based on'' FreeBSD.

    The claim you make implies that darwin and FreeBSD are basically
    interchangeable, which they are not. If you want to argue the point, you
    might do so by providing a stock FreeBSD installation replacing darwin
    in macosx, that is with with at least aqua and aqua using applications
    running on top, on intel or ppc, your choice.


    --
    j p d (at) d s b (dot) t u d e l f t (dot) n l .
    This message was originally posted on Usenet in plain text.
    Any other representation, additions, or changes do not have my
    consent and may be a violation of international copyright law.

  12. Re: Script for updating cached PDF man-pages

    In article <57bfdfF2cerhnU1@mid.individual.net>, jpd
    wrote:

    >> >> > Mac OS X has a FreeBSD in the bottom.
    > >>
    > >> No, it hasn't. It borrows quite a lot from FreeBSD, but that doesn't
    > >> mean you can equate one with the other, any more than you can equate
    > >> FreeBSD with NetBSD or OpenBSD. In fact, in quite a few ways darwin is
    > >> very different from the other *BSDs. At the very least different enough
    > >> to make your statement inaccurate in the general case.

    > >
    > > Well, the Mac OS X version has Mach in the bottom, whereas FreeBSD has its
    > > own kernel, and the latter was written for Intel chips, whereas the
    > > version I am running is for PPC chips. So there are some differences
    > > clearly. What do you have in your mind?

    >
    > Exactly that. Your statement is inaccurate and misleading.
    >
    > The differences go much further. If you would care to know the details,
    > apple provides a lot of documentation on developer.apple.com. It does
    > not, however, claim that darwin ``is a'' FreeBSD, merely that it is
    > ``based on'' FreeBSD.
    >
    > The claim you make implies that darwin and FreeBSD are basically
    > interchangeable, which they are not. If you want to argue the point, you
    > might do so by providing a stock FreeBSD installation replacing darwin
    > in macosx, that is with with at least aqua and aqua using applications
    > running on top, on intel or ppc, your choice.


    But the context was to explain why sh is in /bin/. Are you comments
    relevant to that?

    --
    Hans Aberg

  13. Re: Script for updating cached PDF man-pages

    Begin
    On 2007-04-02, Hans Aberg wrote:
    > But the context was to explain why sh is in /bin/. Are you comments
    > relevant to that?


    My comments were primarily directed at your statement, which was
    overbroad for that context to start with. Further, the /bin/sh on darwin
    appears to be bash, where the FreeBSD /bin/sh very much is not bash.

    Does that answer your question?


    --
    j p d (at) d s b (dot) t u d e l f t (dot) n l .
    This message was originally posted on Usenet in plain text.
    Any other representation, additions, or changes do not have my
    consent and may be a violation of international copyright law.

  14. Re: Script for updating cached PDF man-pages

    In article <57c03gF2cbo46U1@mid.individual.net>, jpd
    wrote:

    > > But the context was to explain why sh is in /bin/. Are you comments
    > > relevant to that?

    >
    > My comments were primarily directed at your statement, which was
    > overbroad for that context to start with.


    My comments were exactly right for the context.

    > Further, the /bin/sh on darwin
    > appears to be bash, where the FreeBSD /bin/sh very much is not bash.


    You might try /bin/sh --version

    > Does that answer your question?


    Yes: your comments are wholly irrelevant.

    --
    Hans Aberg

  15. Re: Script for updating cached PDF man-pages

    Begin
    On 2007-04-02, Hans Aberg wrote:
    >> Further, the /bin/sh on darwin
    >> appears to be bash, where the FreeBSD /bin/sh very much is not bash.

    >
    > You might try /bin/sh --version


    > uname -sr

    FreeBSD 5.4-RELEASE-p4
    > /bin/sh --version

    Illegal option --
    >


    Seems to me you can't stand to admit you happened to be wrong here,
    opting instead to try and hide behind irrelevancy. You're still welcome
    to show a running aqua on stock FreeBSD to demonstrate darwin is as
    close to FreeBSD as you claimed after all. It would be interesting to
    see in itself, even. But I don't think you can do that either.


    --
    j p d (at) d s b (dot) t u d e l f t (dot) n l .
    This message was originally posted on Usenet in plain text.
    Any other representation, additions, or changes do not have my
    consent and may be a violation of international copyright law.

  16. Re: Script for updating cached PDF man-pages

    In article <57c40lF2c9lcbU1@mid.individual.net>, jpd
    wrote:

    > Seems to me you can't stand to admit you happened to be wrong here,
    > opting instead to try and hide behind irrelevancy. You're still welcome
    > to show a running aqua on stock FreeBSD to demonstrate darwin is as
    > close to FreeBSD as you claimed after all. It would be interesting to
    > see in itself, even. But I don't think you can do that either.


    I never made a statement as to how close the OS's are: you are jumping to
    conclusions. The context was to indicate that the file position was as on
    BSD-systems. So you are wholly wrong all the time. It is obvious also from
    the way you put words into others mouth. By jumping in with wholly
    irrelevant comment, you*succeeded in destroying the topic of the thread
    altogether. Continue like that, and the common knowledge base will
    deteriorate. :-)

    --
    Hans Aberg

  17. Re: Script for updating cached PDF man-pages

    Begin
    On 2007-04-02, Hans Aberg wrote:
    > In article <57c40lF2c9lcbU1@mid.individual.net>, jpd
    > wrote:
    >
    >> Seems to me you can't stand to admit you happened to be wrong here,
    >> opting instead to try and hide behind irrelevancy. You're still welcome
    >> to show a running aqua on stock FreeBSD to demonstrate darwin is as
    >> close to FreeBSD as you claimed after all. It would be interesting to
    >> see in itself, even. But I don't think you can do that either.

    >
    > I never made a statement as to how close the OS's are: you are jumping to
    > conclusions. The context was to indicate that the file position was as on
    > BSD-systems. So you are wholly wrong all the time. It is obvious also from
    > the way you put words into others mouth.


    You said, and I quote: ``Mac OS X has a FreeBSD in the bottom.'' This
    is far too broad a statement to implicitly restrict to a context you
    tried twice now to narrow ex post facto into uselessness, apparently
    solely to wriggle your person out from under the target of my criticism,
    which wasn't directed at persons in the first place.

    The systems differ, even the shells provided as /bin/sh differ. If some
    feature in both shells happens to work the same, that is too narrow a
    similarity to effectively equate darwin, which is what apple says serves
    as the underpinnings of ``Mac OS X'', and FreeBSD, which you claimed as
    serving that role. How it is obvious that quoting you is putting words
    in your mouth is a little beyond me, but it doesn't really surprise me
    it apparently makes sense to you.


    > By jumping in with wholly irrelevant comment, you*succeeded in
    > destroying the topic of the thread altogether. Continue like that, and
    > the common knowledge base will deteriorate. :-)


    It's not irrelevant for a technical subject like this: Too often people
    hear this half-truth and assume things, directly or by extrapolation,
    that aren't true, because as much as they share code, the OSen aren't
    interchangeable.

    That the thread drew on and on is at least as much to blame to your
    apparent inability to admit ever making an error, or maybe your
    insistence to take criticisms to actions as personal attacks. As to
    deteriorating knowledge bases, I think outright lying does more to that
    than insisting on correctness. Computing isn't a huggy-feely social
    science, however much the luser crowd wants it to be.

    But then, you have shown yourself to be quite inept at even making a
    solid argument --which requires you don't lie, at least not provably--,
    so I'll leave you to your cosy little world. Good day.


    --
    j p d (at) d s b (dot) t u d e l f t (dot) n l .
    This message was originally posted on Usenet in plain text.
    Any other representation, additions, or changes do not have my
    consent and may be a violation of international copyright law.

  18. Re: Script for updating cached PDF man-pages

    In article <57dvafF2cf3u1U1@mid.individual.net>, jpd
    wrote:

    > > I never made a statement as to how close the OS's are: you are jumping to
    > > conclusions. The context was to indicate that the file position was as on
    > > BSD-systems. So you are wholly wrong all the time. It is obvious also from
    > > the way you put words into others mouth.

    >
    > You said, and I quote: ``Mac OS X has a FreeBSD in the bottom.'' This
    > is far too broad a statement to implicitly restrict to a context


    It was directed towards a person*apparently specializing writing POSIX
    scripts, perhaps with no*interest in the Mac OS X, and by that line
    fully*understood what was meant.

    > ... you
    > tried twice now to narrow ex post facto into uselessness, apparently
    > solely to wriggle your person out from under the target of my criticism,
    > which wasn't directed at persons in the first place.


    How you reinterpret what was obvious to*intelligent people is wholly
    irrelevant. If I should try to cover up all possible useless
    misinterpretations, it would be impossible with any public discussions.

    > The systems differ, even the shells provided as /bin/sh differ. If some
    > feature in both shells happens to work the same, that is too narrow a
    > similarity to effectively equate darwin, which is what apple says serves
    > as the underpinnings of ``Mac OS X'', and FreeBSD, which you claimed as
    > serving that role. How it is obvious that quoting you is putting words
    > in your mouth is a little beyond me, but it doesn't really surprise me
    > it apparently makes sense to you.


    I want to know where the sub-shell was created twice and to fix the
    problem of multiple man-pages with the same name, and not discuss
    the*worthless*garbage everybody already knows that you keep littering the
    USenet with.

    > > By jumping in with wholly irrelevant comment, you*succeeded in
    > > destroying the topic of the thread altogether. Continue like that, and
    > > the common knowledge base will deteriorate. :-)

    >
    > It's not irrelevant for a technical subject like this: Too often people
    > hear this half-truth and assume things, directly or by extrapolation,
    > that aren't true, because as much as they share code, the OSen aren't
    > interchangeable.


    It doesn't help*forwarding the topic at hand. Start another thread where
    it is on topic. Get off my back.

    > That the thread drew on and on is at least as much to blame to your
    > apparent inability to admit ever making an error, or maybe your
    > insistence to take criticisms to actions as personal attacks. As to
    > deteriorating knowledge bases, I think outright lying does more to that
    > than insisting on correctness. Computing isn't a huggy-feely social
    > science, however much the luser crowd wants it to be.


    You are wholly wrong all the time, and don't want to admit it.

    > But then, you have shown yourself to be quite inept at even making a
    > solid argument --which requires you don't lie, at least not provably--,
    > so I'll leave you to your cosy little world. Good day.


    Please don't litter the Usenet with this useless garbage.

    Hans Aberg

+ Reply to Thread