Created
December 6, 2021 16:33
-
-
Save gwpl/88434282fc7d3a67533ef53bf739b7f2 to your computer and use it in GitHub Desktop.
print code with syntax highlighting using Vim's hardcopy
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 | |
tmpd="$(mktemp -d)" | |
mergedpdf=merged_source_files.pdf | |
if [ "$1" == "-o" ]; then | |
mergedpdf="$2" | |
shift 2 | |
fi | |
idx=00 | |
while [ "$1" != "" ]; do | |
fn="$1" | |
shift 1 | |
echo Converting "$fn"... | |
idxstr="$(printf "%03d%s\n" $idx)" | |
idx=$((idx + 1)) | |
ps_fn="$tmpd/out-$idxstr.ps" | |
pdf_fn="$tmpd/out-$idxstr.pdf" | |
vim -c 'set printoptions=number:y' -c "hardcopy > $ps_fn" -c quit "$fn" | |
ps2pdf "$ps_fn" "$pdf_fn" | |
done | |
set -x | |
pwd | |
echo "Merging into $mergedpdf" | |
pdfunite "$tmpd"/*.pdf "$mergedpdf" | |
rm -r "${tmpd}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment