83 lines
2.2 KiB
Bash
Executable file
83 lines
2.2 KiB
Bash
Executable file
#! /bin/bash
|
|
|
|
version=1.0
|
|
editor=$USER
|
|
title=''
|
|
file=
|
|
ending=tex
|
|
# path to this script
|
|
script=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
|
|
|
|
|
|
Help() {
|
|
echo Tool to convert file from markdown to another format
|
|
echo Usage: pandocPipeline [OPTION] [COMMAND]
|
|
echo -h, --help show this help screen
|
|
echo -f, --file specify filename without extension
|
|
echo -e, --ending spefify target file format
|
|
echo -u, --user=editor enter name of file editor set between "" \(only for target format pdf\)
|
|
echo -t, --title enter title of document set between "" \(only for target format pdf\)
|
|
echo Pipeline is optimized for target format pdf and docx but works with others as well
|
|
echo Possible fileformats see: https://pandoc.org/diagram.svgz?v=20230203095535
|
|
echo Examples:
|
|
echo: md -> pdf : pandocPipeline -u "Dokumentbearbeiter" -t "Dokumententitel" -f dateiname -e pdf
|
|
echo: md -> docx : pandocPipeline -f dateiname -e docx
|
|
}
|
|
|
|
Error() {
|
|
echo An error occured
|
|
echo Try 'pandocPipeline --help' for more information
|
|
}
|
|
|
|
Errorfile() {
|
|
echo No file was given
|
|
echo Please add a filename to your command
|
|
echo Try 'pandocPipeline --help' for more information
|
|
}
|
|
|
|
ARGS=$(getopt -a --options hvutfe --long "help, version, user, title, file, ending" -- "$@")
|
|
|
|
eval set -- "$ARGS"
|
|
|
|
while true; do
|
|
case "$1" in
|
|
-u|--user)
|
|
editor=$2
|
|
shift 2;;
|
|
-t|--title)
|
|
title=$2
|
|
shift 2;;
|
|
-f|--file)
|
|
file=$2
|
|
shift 2;;
|
|
-e|--ending)
|
|
ending=$2
|
|
shift 2;;
|
|
-v|--version)
|
|
echo mktex $version
|
|
exit;;
|
|
-h|--help)
|
|
Help
|
|
exit;;
|
|
--)
|
|
break;
|
|
esac
|
|
done
|
|
|
|
if [[ -z "$file" ]]; then
|
|
Errorfile
|
|
exit
|
|
fi
|
|
|
|
if [[ "$ending" == "pdf" ]]
|
|
header=$script/header.md
|
|
sedfile=$script/body.sed
|
|
picture=$script/Logo.png
|
|
sed -i 's,Editor:.*,Editor: '$editor' \\\\\\\\,' $header
|
|
sed -i 's,Title:.*,Title: '$title',' $header
|
|
sed -i 's,textwidth]{.*,textwidth]{'%picture%'}},' $header
|
|
cat %file%.md $header | sed -E -f $sedfile| pandoc --filter $pandocenv --number-sections --toc -i - -o $file.pdf
|
|
xdg-open $file.pdf
|
|
fi
|
|
|
|
|