Results 1 to 1 of 1

Thread: Shell script to browse installed package documentation

  1. #1
    Join Date
    Feb 2013

    Shell script to browse installed package documentation

    Attached tarball (doc.tar.gz) contains shell scripts to browse documentation installed in /usr/share/doc

    They are similar in function to debmany(1) from the package debian-goodies.

    The main script is doc.bash. Just rename it 'doc' and put somewhere on $PATH. For convenience, I also prepared a very basic .deb with it. It's here (unsigned). The source package is there, too.

    Contents of the tarball
    • doc.bash - this is all you need.
    • - the same script rewritten for /bin/sh.
    • - ditto, strictly POSIX-compliant.
    • - ditto, for legacy Bourne shell.
    •* - dumbed down versions using 'select' (bash and zsh).
    • completion.* - completion code (bash and tcsh).
    • compctl.zsh - completion code for zsh, using the 'old' completion subsystem.
    • compsys.zsh - ditto, using the 'new' completion subsystem.
    • _doc - completion function for zsh (to put in $fpath).
    • doc - completion function for yash (to put in $YASH_LOADPATH).

    For most purposes, the simplified versions (*) should be enough. Below is the code of ''. It gives the idea of what the scripts do.
    #!/bin/bash -e
    [[ -n $1 ]] || { echo "Usage: $0 package_name" >&2; exit 1;}
    [[ -d $docpfx$1 ]] || { echo "Directory $docpfx$1 not found" >&2; exit 2;}
    : ${COLUMNS:=`tput cols`}
    lsopts='-Ldpq --group-directories-first'
    shopt -s extglob nullglob checkwinsize
    idx=index?(.[a-z][a-z]*).htm?(l) CDPATH=
    docmenu () {
      pushd "$1" >/dev/null
      local PS3="...${PWD#$docpfx}> "
      # Grouping index.html first, directories next, then all the rest.
      local -a files=($idx)
      mapfile -tO${#files[@]} files < <(ls $lsopts !($idx))
      select file in "${files[@]}"; do
        [[ $REPLY == [Xx]* ]] && exit
        [[ -z $file ]] && break
        if [[ -d $file ]]; then
          docmenu "$file"
          case $file in
            *.htm?(l)) sensible-browser "$file";;
            *)         sensible-pager   "$file";;
      popd >/dev/null
    pushd "$docpfx" >/dev/null
    docmenu "$1"
    popd >/dev/null
    The crude bash completion code for the 'doc' command:
    _doc(){ [[ $COMP_CWORD -eq 1 && $2 == -* ]] && COMPREPLY=(--auto-redisplay);}
    complete -W "`cd /usr/share/doc; echo *`" -F _doc doc
    Last edited by schragge; May 4th, 2013 at 06:18 PM. Reason: link fix

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts