Skip to content

Instantly share code, notes, and snippets.

@gwpl
Created December 6, 2021 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gwpl/88434282fc7d3a67533ef53bf739b7f2 to your computer and use it in GitHub Desktop.
Save gwpl/88434282fc7d3a67533ef53bf739b7f2 to your computer and use it in GitHub Desktop.
print code with syntax highlighting using Vim's hardcopy
#!/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