Consolidate document creation scripts and fix bugs
Replace the individual new_knitr_document, new_tex_assignment, and new_tex_letter scripts with a single new_tex_document script that takes a document type as its first argument. Fix bugs present in all scripts: unquoted variables, TMPDIR name collision, missing existence checks, and mktemp running unconditionally. Add cdsc_tex_aliases.sh for backwards compatibility with old script names. Add rename_tex_to_dirname script (moved from ~/bin). Update README and wiki page to reflect new setup. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,22 +1,64 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Helper script to export LaTeX templates for new documents
|
||||
# Copyright (c) 2009-2016 Benjamin Mako Hill <mako@atdot.cc>
|
||||
# Helper script to export LaTeX/knitr templates for new documents
|
||||
# Copyright (c) 2009-2026 Benjamin Mako Hill <mako@atdot.cc>
|
||||
# Released under the GPLv3 or later.
|
||||
|
||||
set -e
|
||||
|
||||
CURDIR=$(pwd)
|
||||
TMPDIR=$(mktemp -d)
|
||||
|
||||
if test $1
|
||||
then
|
||||
cd "$HOME/tex/cdsc_tex"
|
||||
git archive --format=tar master paper_template|tar x --strip=1 -C "$TMPDIR"
|
||||
cd "$CURDIR"
|
||||
usage() {
|
||||
echo "Usage: $(basename "$0") <type> <directory>"
|
||||
echo "Types: paper, assignment, knitr, letter"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# get rid of paper_template subdir
|
||||
mv "$TMPDIR" "$1"
|
||||
cd "$1";
|
||||
mv "text.tex" "$1.tex"
|
||||
else
|
||||
echo "specifiy a directory where the template should go";
|
||||
[ -n "$1" ] && [ -n "$2" ] || usage
|
||||
|
||||
TYPE="$1"
|
||||
DEST="$2"
|
||||
|
||||
case "$TYPE" in
|
||||
paper)
|
||||
REPO="$HOME/tex/cdsc_tex"
|
||||
BRANCH="master"
|
||||
TEMPLATE="paper_template"
|
||||
EXT="tex"
|
||||
;;
|
||||
assignment)
|
||||
REPO="$HOME/tex/cdsc_tex"
|
||||
BRANCH="master"
|
||||
TEMPLATE="assignment_template"
|
||||
EXT="tex"
|
||||
;;
|
||||
knitr)
|
||||
REPO="$HOME/tex/cdsc_tex"
|
||||
BRANCH="knitr"
|
||||
TEMPLATE="paper_template"
|
||||
EXT="Rtex"
|
||||
;;
|
||||
letter)
|
||||
REPO="$HOME/tex/cdsc_tex"
|
||||
BRANCH="master"
|
||||
TEMPLATE="letter_template"
|
||||
EXT="tex"
|
||||
;;
|
||||
*)
|
||||
echo "error: unknown type '$TYPE'"
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -e "$DEST" ]; then
|
||||
echo "error: '$DEST' already exists"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
WORK_DIR=$(mktemp -d)
|
||||
cd "$REPO"
|
||||
git archive --format=tar "$BRANCH" "$TEMPLATE" | tar x --strip=1 -C "$WORK_DIR"
|
||||
cd "$CURDIR"
|
||||
mv "$WORK_DIR" "$DEST"
|
||||
cd "$DEST"
|
||||
mv "text.$EXT" "$(basename "$DEST").$EXT"
|
||||
|
||||
Reference in New Issue
Block a user