~theorytoe/mman

d60d26afbf48e2b687d2099271f0b3c54f15f567 — theorytoe 6 months ago 6a4bdb6
(mman) add: color support
2 files changed, 61 insertions(+), 27 deletions(-)

M mman
M mman.1
M mman => mman +39 -17
@@ 6,19 6,31 @@
MMANDIR=${MMANDIR:-~/.mman}
SRCDIR=${MMANDIR}/scd
EDITOR=${EDITOR:-nano}
PAGER=${PAGER:-less}

SECTION="0 1 2 3 4 5 6 7 8 9"

ACTION=view

[ -d "$MMANDIR" ] || mkdir -p "$MMANDIR"
[ -d "$SRCDIR" ] || mkdir -p "$SRCDIR"

# add coloring to manpages
export LESS_TERMCAP_md=$(tput bold; tput setaf 4)
export LESS_TERMCAP_me=$(tput sgr0)
export LESS_TERMCAP_mb=$(tput blink)
export LESS_TERMCAP_us=$(tput smul; tput setaf 2)
export LESS_TERMCAP_ue=$(tput rmul; tput sgr0)
export LESS_TERMCAP_so=$(tput smso)
export LESS_TERMCAP_se=$(tput rmso)

istty() {
	stty > /dev/null 2>&1
	return $?
}

editman() {
	# search for name in all sections
	for i in $SECTION; do
		file="${MMANDIR}/$1.$i.txt"
		if [ -f "$file" ]; then


@@ 26,11 38,17 @@ editman() {
			return $?
		fi
	done
	# touch ${MMANDIR}/$1.7.txt
	"$EDITOR" "${MMANDIR}/$1.7.txt"
	return $?

	# if we cant find a page, edit with the first
	# possible section (0) if unset. If the section
	# has been set via option, it defaults to that
	for i in $SECTION; do
		"$EDITOR" "${MMANDIR}/$1.$i.txt"
		return $?
	done
}

# TODO: add support for adding templates
edittroff() {
	for i in $SECTION; do
		file="${MMANDIR}/$1.$i.man"


@@ 39,9 57,10 @@ edittroff() {
			return $?
		fi
	done
	# touch ${MMANDIR}/$1.7.man
	$EDITOR ${MMANDIR}/$1.7.man
	return $?
	for i in $SECTION; do
		"$EDITOR" "${MMANDIR}/$1.$i.man"
		return $?
	done
}

editscdoc() {


@@ 52,9 71,11 @@ editscdoc() {
			return $?
		fi
	done
	# touch ${SRCDIR}/$1.7.scd
	$EDITOR ${SRCDIR}/$1.7.scd
	return $?
	for i in $SECTION; do
		"$EDITOR" "${MMANDIR}/$1.$i.man"
		compileman # compile manpages after edit
		return $?
	done
}

# TODO: rework this to use -exec


@@ 70,16 91,15 @@ viewman() {
		file=${MMANDIR}/$1.$i.man
		if [ -f "$file" ]; then
			if istty; then
				# man "$file"
				cat "$file" | nroff -Tascii -c -mandoc | less -R
				man -mandoc "$file"
			else
				cat "$file" | nroff -Tascii -c -mandoc
				man -mandoc "$file"
			fi
		fi
		file=${MMANDIR}/$1.$i.txt
		if [ -f "$file" ]; then
			if istty; then
				less "$file"
				$PAGER "$file"
			else
				cat "$file"
			fi


@@ 90,8 110,8 @@ viewman() {
usage() {
	cat << EOF
usage: $(basename $0) [-e|-t|-s|-c|-l] [section] name
    -e Edit a troff -man manpage
    -t Edit a txt man page
    -e Edit a txt man page
    -t Edit a troff -man manpage
    -s Edit an scdoc manpage
    -c Compile scdoc manpages
    -l List available pages


@@ 117,11 137,13 @@ while [ $# -gt 0 ]; do
			compileman
			exit $?;;
		-l)
			# XXX: should I keep this here?
			compileman
			# XXX: should I keep this here? no
			find $MMANDIR -not -type d \
				-exec basename {} ';'
			exit $?;;
		-h|--help)
			usage
			exit $?;;
		[1234567890])
			SECTION=$1
			shift;;

M mman.1 => mman.1 +22 -10
@@ 1,7 1,7 @@
.\" 
.TH mman 1 2022-11-20 "mman 0.0-a"
.SH NAME
mman - write personal manpages
mman \- write personal mmanpages

.SH SYNPOSYS
.B mman


@@ 11,7 11,10 @@ mman - write personal manpages

.SH DESCRIPTION
Create man pages for personal documentation using plaintext, \fBtroff\fR(1), and \fBscdoc\fR(1)
syntax.
syntax. Pages are organized by section, similar to traditional manpages, but without the strict
requirement to conform to those standards. If a 
.I secion
Is not specified, new pages will default to secion 0, a non-standard section.

.TP
\fB \-e \fR


@@ 30,24 33,33 @@ Edit an scdoc man page. Compiles pages after edit.
Compile scdoc manpages.

.TP
\fB \-t \fR
\fB \-l \fR
List available pages.

.SH NOTES
Be wary of pages written with scdoc. If a troff and scdoc page are named the same, compiling
an scdoc page will overwrite the existsing troff page.
an scdoc page will overwrite the existsing troff page. This is intended behavior.

.PP
Man pages are shown with colors using \fBless\fR(1) termcap environment vars.

.SH AUTHOR
Written by theorytoe
.UR https://theoryware.net
.UE
and contributors.
Written by theorytoe <\fBhttps://theoryware.net\fR> and contributors.

.SH BUG REPORTS
Bug reports and patches can be sent to the mailing list
<\fB~theorytoe/public-inbox@lists.sr.ht\fR>

.PP
Patches sent must have in the 
.I mman
in the subject line ([PATCH \fImman\fR]).

.SH COPYRIGHT
Copyright © 2022 theorytoe and authors. Lisenced under GPLv3.
Copyright © 2022 theorytoe and authors. Licensed under GPLv3.
.PP
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to
the extent permitted by law.

.SH SEE ALSO
\fBman\fR(7) \fBman-pages\fR(7) \fBnroff\fR(1) \fBtroff\fR(1) \fBscdoc\fR(5)
\fBman\fR(7) \fBman-pages\fR(7) \fBnroff\fR(1) \fBtroff\fR(1) \fBscdoc\fR(5) \fBless\fR(1)