| 1 | #!/bin/bash |
| 2 | # maned.sh |
| 3 | # A rudimentary man page editor |
| 4 | |
| 5 | # Version: 0.1 (Alpha, probably buggy) |
| 6 | # Author: Mendel Cooper <[email protected]> |
| 7 | # Reldate: 16 June 2008 |
| 8 | # License: GPL3 |
| 9 | |
| 10 | |
| 11 | savefile= # Global, used in multiple functions. |
| 12 | E_NOINPUT=90 # User input missing (error). May or may not be critical. |
| 13 | |
| 14 | # =========== Markup Tags ============ # |
| 15 | TopHeader=".TH" |
| 16 | NameHeader=".SH NAME" |
| 17 | SyntaxHeader=".SH SYNTAX" |
| 18 | SynopsisHeader=".SH SYNOPSIS" |
| 19 | InstallationHeader=".SH INSTALLATION" |
| 20 | DescHeader=".SH DESCRIPTION" |
| 21 | OptHeader=".SH OPTIONS" |
| 22 | FilesHeader=".SH FILES" |
| 23 | EnvHeader=".SH ENVIRONMENT" |
| 24 | AuthHeader=".SH AUTHOR" |
| 25 | BugsHeader=".SH BUGS" |
| 26 | SeeAlsoHeader=".SH SEE ALSO" |
| 27 | BOLD=".B" |
| 28 | # Add more tags, as needed. |
| 29 | # See groff docs for markup meanings. |
| 30 | # ==================================== # |
| 31 | |
| 32 | start () |
| 33 | { |
| 34 | clear # Clear screen. |
| 35 | echo "ManEd" |
| 36 | echo "-----" |
| 37 | echo |
| 38 | echo "Simple man page creator" |
| 39 | echo "Author: Mendel Cooper" |
| 40 | echo "License: GPL3" |
| 41 | echo; echo; echo |
| 42 | } |
| 43 | |
| 44 | progname () |
| 45 | { |
| 46 | echo -n "Program name? " |
| 47 | read name |
| 48 | |
| 49 | echo -n "Manpage section? [Hit RETURN for default (\"1\") ] " |
| 50 | read section |
| 51 | if [ -z "$section" ] |
| 52 | then |
| 53 | section=1 # Most man pages are in section 1. |
| 54 | fi |
| 55 | |
| 56 | if [ -n "$name" ] |
| 57 | then |
| 58 | savefile=""$name"."$section"" # Filename suffix = section. |
| 59 | echo -n "$1 " >>$savefile |
| 60 | name1=$(echo "$name" | tr a-z A-Z) # Change to uppercase, |
| 61 | #+ per man page convention. |
| 62 | echo -n "$name1" >>$savefile |
| 63 | else |
| 64 | echo "Error! No input." # Mandatory input. |
| 65 | exit $E_NOINPUT # Critical! |
| 66 | # Exercise: The script-abort if no filename input is a bit clumsy. |
| 67 | # Rewrite this section so a default filename is used |
| 68 | #+ if no input. |
| 69 | fi |
| 70 | |
| 71 | echo -n " \"$section\"">>$savefile # Append, always append. |
| 72 | |
| 73 | echo -n "Version? " |
| 74 | read ver |
| 75 | echo -n " \"Version $ver \"">>$savefile |
| 76 | echo >>$savefile |
| 77 | |
| 78 | echo -n "Short description [0 - 5 words]? " |
| 79 | read sdesc |
| 80 | echo "$NameHeader">>$savefile |
| 81 | echo ""$BOLD" "$name"">>$savefile |
| 82 | echo "\- "$sdesc"">>$savefile |
| 83 | |
| 84 | } |
| 85 | |
| 86 | fill_in () |
| 87 | { # This function more or less copied from "pad.sh" script. |
| 88 | echo -n "$2? " # Get user input. |
| 89 | read var # May paste (a single line only!) to fill in field. |
| 90 | |
| 91 | if [ -n "$var" ] |
| 92 | then |
| 93 | echo "$1 " >>$savefile |
| 94 | echo -n "$var" >>$savefile |
| 95 | else # Don't append empty field to file. |
| 96 | return $E_NOINPUT # Not critical here. |
| 97 | fi |
| 98 | |
| 99 | echo >>$savefile |
| 100 | |
| 101 | } |
| 102 | |
| 103 | |
| 104 | end () |
| 105 | { |
| 106 | clear |
| 107 | echo -n "Would you like to view the saved man page (y/n)? " |
| 108 | read ans |
| 109 | if [ "$ans" = "n" -o "$ans" = "N" ]; then exit; fi |
| 110 | exec less "$savefile" # Exit script and hand off control to "less" ... |
| 111 | #+ ... which formats for viewing man page source. |
| 112 | } |
| 113 | |
| 114 | |
| 115 | # ---------------------------------------- # |
| 116 | start |
| 117 | progname "$TopHeader" |
| 118 | fill_in "$SynopsisHeader" "Synopsis" |
| 119 | fill_in "$DescHeader" "Long description" |
| 120 | # May paste in *single line* of text. |
| 121 | fill_in "$OptHeader" "Options" |
| 122 | fill_in "$FilesHeader" "Files" |
| 123 | fill_in "$AuthHeader" "Author" |
| 124 | fill_in "$BugsHeader" "Bugs" |
| 125 | fill_in "$SeeAlsoHeader" "See also" |
| 126 | # fill_in "$OtherHeader" ... as necessary. |
| 127 | end # ... exit not needed. |
| 128 | # ---------------------------------------- # |
| 129 | |
| 130 | # Note that the generated man page will usually |
| 131 | #+ require manual fine-tuning with a text editor. |
| 132 | # However, it's a distinct improvement upon |
| 133 | #+ writing man source from scratch |
| 134 | #+ or even editing a blank man page template. |
| 135 | |
| 136 | # The main deficiency of the script is that it permits |
| 137 | #+ pasting only a single text line into the input fields. |
| 138 | # This may be a long, cobbled-together line, which groff |
| 139 | # will automatically wrap and hyphenate. |
| 140 | # However, if you want multiple (newline-separated) paragraphs, |
| 141 | #+ these must be inserted by manual text editing on the |
| 142 | #+ script-generated man page. |
| 143 | # Exercise (difficult): Fix this! |
| 144 | |
| 145 | # This script is not nearly as elaborate as the |
| 146 | #+ full-featured "manedit" package |
| 147 | #+ http://freshmeat.net/projects/manedit/ |
| 148 | #+ but it's much easier to use. |