summaryrefslogtreecommitdiff
path: root/man2pdf
diff options
context:
space:
mode:
authorMatias Linares <mlm0111@famaf.unc.edu.ar>2013-10-20 17:10:56 -0300
committerMatias Linares <mlm0111@famaf.unc.edu.ar>2013-10-20 17:10:56 -0300
commitad0f062b584661062863df4a5c2ae4d958f5b687 (patch)
tree993279ccd576c7e442d61f151690f7d666771c50 /man2pdf
downloadman2pdf-ad0f062b584661062863df4a5c2ae4d958f5b687.tar.gz
first commit
Diffstat (limited to 'man2pdf')
-rwxr-xr-xman2pdf70
1 files changed, 70 insertions, 0 deletions
diff --git a/man2pdf b/man2pdf
new file mode 100755
index 0000000..9ff3d75
--- /dev/null
+++ b/man2pdf
@@ -0,0 +1,70 @@
+#!/bin/bash
+
+# Autor: Matias Linares <mlm0111@famaf.unc.edu.ar>
+
+VIEWER=evince
+PARAMS=("$@")
+re='^[0-9]+$'
+
+function usage {
+ printf "$0 [CHAPTER] [MANPAGE] [FILE]\n\n"
+ printf "Convierte una pagina de manual a pdf. Si el archivo para guardarlo\n"
+ printf "no esta definido, se abrira con el visor de pdf de su preferencia.\n\n"
+
+ printf "[CHAPTER] y [FILE] Pueden ser omitidos tranquilamente.\n"
+}
+
+function isnumber {
+ num=$1
+ if ! [[ $num =~ $re ]]; then
+ echo 0
+ else
+ echo 1
+ fi
+}
+
+assert_manpage() {
+ man -t $1 $2 > /dev/null || exit 1
+}
+
+
+if [ ${#PARAMS[*]} -eq 0 ] || [ ${#PARAMS[*]} -gt 3 ] ||
+ [ "${PARAMS[0]}" = "-h" ] || [ "${PARAMS[0]}" = "--help" ]
+then
+ # Fallan los parametros o queremos ver la ayuda :p
+ usage
+elif [ ${#PARAMS[*]} -eq 1 ]
+then
+ # Un solo parametro
+ assert_manpage ${PARAMS[0]}
+ name="/tmp/${PARAMS[0]}.pdf"
+ manpage=${PARAMS[0]}
+ man -t $manpage | ps2pdf - > "$name"
+ $VIEWER $name 2> /dev/null &
+elif [ ${#PARAMS[*]} -eq 2 ]
+then
+ # Son dos parametros.
+ if [ $(isnumber ${PARAMS[0]}) -eq 0 ]
+ then
+ # Tenemos un archivo al que escribir
+ assert_manpage ${PARAMS[0]}
+ manpage=${PARAMS[0]}
+ name="${PARAMS[1]}"
+ man -t ${PARAMS[0]} | ps2pdf - > "${PARAMS[1]}"
+ else
+ # Vemos el archivo con su respectiva pagina de manual
+ assert_manpage ${PARAMS[0]} ${PARAMS[1]}
+ name="/tmp/${PARAMS[1]}${PARAMS[0]}.pdf"
+ chapter=${PARAMS[0]}
+ manpage=${PARAMS[1]}
+ man -t $chapter $manpage | ps2pdf - > "$name"
+ $VIEWER $name 2> /dev/null &
+ fi
+else
+ name="${PARAMS[2]}"
+ chapter=${PARAMS[0]}
+ manpage=${PARAMS[1]}
+ man -t $chapter $manpage | ps2pdf - > "$name"
+fi
+
+exit 0