-
-
Save robotanarchy/16ca1d06d26e306c3062 to your computer and use it in GitHub Desktop.
add global flag to regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This script caches the pygmentize output. | |
# Original script by michih57 | |
# | |
# Modifications by robotanarchy: | |
# - remove real_pygmentize variable | |
# - store hash in 'out' folder | |
# - replace '\$' with '$' to fix syntax highlighting in editors | |
# - also cache style information | |
# - add .cache extension (useful for gitignore) | |
# | |
# Example usage (add this to your preamble): | |
# \usepackage[outputdir=out]{minted} | |
# \renewcommand{\MintedPygmentize}{scripts/pygmentize.sh} | |
# \usemintedstyle{manni} | |
# | |
outputdir="out" | |
# get the output file, if any | |
take_outfile=0 | |
for arg in $@; do | |
[ $take_outfile -eq 1 ] && outfile=$arg && break | |
[ $arg == -o ] && take_outfile=1 | |
done | |
# when called without an output file, minted expects | |
# the output on stdout (this gets used for style information). | |
# We'll use a hash of the commandline in that case. | |
if [ "$outfile" == "" ]; then | |
hash="$outputdir/$( echo "$*" | md5sum | cut -d' ' -f1 ).cache" | |
[ -f "$hash" ] || pygmentize $* > $hash | |
cat $hash | |
exit 0 | |
fi | |
# Otherwise: the last parameter is the input file | |
infile=${@: -1} | |
# compute the hash value of the input | |
hash="$outputdir/$( md5sum $infile | cut -d' ' -f1 ).cache" | |
if [ -f "$hash" ]; then | |
# we have cached output from pygmentize | |
cp "$hash" "$outfile" | |
else | |
# fix syntax highlighting issues with '$' | |
sed --in-place -e's~\\\$~\$~g' "$infile" | |
pygmentize $* | |
cp "$outfile" "$hash" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: minted 2.0 has cache support built-in. It's still useful for me to replace
\$
with$
.