Last active
June 17, 2020 16:57
-
-
Save robwhess/430e4138e015a9c634ba500f4150a30b to your computer and use it in GitHub Desktop.
Script for printing a code project to PDF
This file contains hidden or 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
#!/usr/bin/env bash | |
PROJECT_DIR="$1" | |
OUTPUT_FILE="$2" | |
if [[ -z "$PROJECT_DIR" ]] || [[ -z "$OUTPUT_FILE" ]]; then | |
echo "usage: `basename $0` <project_dir> <output_pdf>" | |
exit | |
fi | |
TMP_FILE=`mktemp` || exit 1 | |
PS_FILE="$TMP_FILE.ps" | |
mv "$TMP_FILE" "$PS_FILE" | |
echo "== Processing README" | |
find "$PROJECT_DIR" \( -path "*node_modules" -o -path "*.git" \) -prune -o \ | |
-iname "README*" \ | |
-exec enscript -1rG --line-numbers --color=1 --word-wrap -p - \{\} \; >> "$PS_FILE" | |
# Web project code | |
echo "== Processing *.js" | |
find "$PROJECT_DIR" \( -path "*node_modules" -o -path "*.git" \) -prune -o \ | |
-iname "*.js" \ | |
-exec enscript -1rG --line-numbers --highlight=javascript --color=1 --word-wrap -p - \{\} \; >> "$PS_FILE" | |
echo "== Processing *.html" | |
find "$PROJECT_DIR" \( -path "*node_modules" -o -path "*.git" \) -prune -o \ | |
-iname "*.html" \ | |
-exec enscript -1rG --line-numbers --highlight=html --color=1 --word-wrap -p - \{\} \; >> "$PS_FILE" | |
echo "== Processing *.handlebars" | |
find "$PROJECT_DIR" \( -path "*node_modules" -o -path "*.git" \) -prune -o \ | |
-iname "*.handlebars" \ | |
-exec enscript -1rG --line-numbers --highlight=html --color=1 --word-wrap -p - \{\} \; >> "$PS_FILE" | |
echo "== Processing *.css" | |
find "$PROJECT_DIR" \( -path "*node_modules" -o -path "*.git" \) -prune -o \ | |
-iname "*.css" \ | |
-exec enscript -1rG --line-numbers --color=1 --word-wrap -p - \{\} \; >> "$PS_FILE" | |
echo "== Processing *.json" | |
find "$PROJECT_DIR" \( -path "*node_modules" -o -path "*.git" \) -prune -o \ | |
-iname "*.json" \ | |
-exec enscript -1rG --line-numbers --highlight=javascript --color=1 --word-wrap -p - \{\} \; >> "$PS_FILE" | |
# C/CPP project code | |
echo "== Processing *.cpp" | |
find "$PROJECT_DIR" \( -path "*.git" \) -prune -o \ | |
-iname "*.cpp" \ | |
-exec enscript -1rG --line-numbers --highlight=cpp --color=1 --word-wrap -p - \{\} \; >> "$PS_FILE" | |
echo "== Processing *.hpp" | |
find "$PROJECT_DIR" \( -path "*.git" \) -prune -o \ | |
-iname "*.hpp" \ | |
-exec enscript -1rG --line-numbers --highlight=cpp --color=1 --word-wrap -p - \{\} \; >> "$PS_FILE" | |
echo "== Processing *.c" | |
find "$PROJECT_DIR" \( -path "*.git" \) -prune -o \ | |
-iname "*.c" \ | |
-exec enscript -1rG --line-numbers --highlight=cpp --color=1 --word-wrap -p - \{\} \; >> "$PS_FILE" | |
echo "== Processing *.h" | |
find "$PROJECT_DIR" \( -path "*.git" \) -prune -o \ | |
-iname "*.h" \ | |
-exec enscript -1rG --line-numbers --highlight=cpp --color=1 --word-wrap -p - \{\} \; >> "$PS_FILE" | |
echo "== Processing Makefiles" | |
find "$PROJECT_DIR" \( -path "*.git" \) -prune -o \ | |
-iname "makefile" \ | |
-exec enscript -1rG --line-numbers --highlight=makefile --color=1 --word-wrap -p - \{\} \; >> "$PS_FILE" | |
# Flex/Bison project code | |
echo "== Processing *.l" | |
find "$PROJECT_DIR" \( -path "*.git" \) -prune -o \ | |
-iname "*.l" \ | |
-exec enscript -1rG --line-numbers --highlight=cpp --color=1 --word-wrap -p - \{\} \; >> "$PS_FILE" | |
echo "== Processing *.y" | |
find "$PROJECT_DIR" \( -path "*.git" \) -prune -o \ | |
-iname "*.y" \ | |
-exec enscript -1rG --line-numbers --highlight=cpp --color=1 --word-wrap -p - \{\} \; >> "$PS_FILE" | |
echo "== PS output to $PS_FILE" | |
echo "== Generating PDF file $OUTPUT_FILE" | |
pstopdf "$PS_FILE" -o "$OUTPUT_FILE" | |
rm -f "$PS_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment