diff --git a/packages/scripts/chunk-pdf b/packages/scripts/chunk-pdf new file mode 100755 index 0000000..86b2b69 --- /dev/null +++ b/packages/scripts/chunk-pdf @@ -0,0 +1,23 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i bash -p pdftk gnugrep +set -efu + +INPUT_FILE="${2:?Pass the PDF path as second argument.}" +PAGES_PER_REPORT="${1:?Pass the chunk size as first argument.}" + +if [ ! -f "$INPUT_FILE" ]; then + echo >&2 "File $INPUT_FILE does not exist." + exit 1 +fi + +TOTAL_PAGES="$(pdftk "$INPUT_FILE" dump_data | grep NumberOfPages | cut -f2 -d' ')" + +RUNS=$((TOTAL_PAGES/PAGES_PER_REPORT)) + +for run in $(seq 0 "$((RUNS-1))"); do + start_page=$((run*PAGES_PER_REPORT+1)) + end_page=$(((run+1)*PAGES_PER_REPORT)) + output_file="chunk_$((run+1)).pdf" + echo "splitting $INPUT_FILE from $start_page to $end_page into $output_file" + pdftk "$INPUT_FILE" cat "$start_page-$end_page" output "$output_file" +done diff --git a/packages/scripts/nix-haddock-index b/packages/scripts/nix-haddock-index new file mode 100755 index 0000000..294e3df --- /dev/null +++ b/packages/scripts/nix-haddock-index @@ -0,0 +1,93 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i bash -p coreutils gnugrep gnused graphviz +# +# usage: nix-haddock-index +# +# Run this script in an environment where either NIX_GHC is set, or the ghc +# executable exists, to generate an HTML index file pointing to all Haddock +# files accessible to the respective ghc version. +# +# Additionally, an SVG dependency graph of all packages is linked at the +# bottom of the index file. +# +# Note: all files will be generated in /tmp, and won't be deleted automatically +# + +set -efux + +if test -z "${NIX_GHC-}"; then + NIX_GHC=$(readlink -f "$(type -P ghc)") +fi + +if ! echo $NIX_GHC | grep -q '^/nix/store/'; then + printf '%s: error: unsupported GHC executable path (not in Nix store): %q\n' \ + "$0" \ + "$NIX_GHC" \ + >&2 + exit -1 +fi + +NIX_GHC_PREFIX=$(dirname "$(dirname "$NIX_GHC")") +NIX_GHC_DOCDIR=$NIX_GHC_PREFIX/share/doc/ghc/html + +main() { + + hash=$(echo $NIX_GHC_PREFIX | sed -n 's|^/nix/store/\([a-z0-9]\+\).*|\1|p') + title="Haddock index for $NIX_GHC_PREFIX" + + header=$( + printf 'Haddock index for %s\n' \ + $NIX_GHC_PREFIX \ + $NIX_GHC_PREFIX \ + ) + + suffix=${hash:+-$hash} + index_file=/tmp/haddock$suffix-index.html + svg_file=/tmp/haddock$suffix.svg + + #if ! test -e $index_file; then + eval "$( + echo 'gen_index() {' + echo ' html_head' + "$NIX_GHC_PREFIX"/bin/ghc-pkg dump | sed -n ' + s/^---$/ reset/p + s/^\(name\|version\):\s*\([-A-Za-z0-9_.]\+\)$/ \1=\2/p + s/^haddock-html:\s*\([-A-Za-z0-9_./]\+\)$/ haddock_html \1/p + ' + echo ' html_foot' + echo '}' + )" + + gen_index > $index_file + #fi + + #if ! test -e $svg_file; then + "$NIX_GHC_PREFIX"/bin/ghc-pkg dot | tred | dot -Tsvg | sed ' + s/ $svg_file + #fi + + echo $index_file +} +reset() { + unset name version +} +haddock_html() { + printf '
  • ' + printf '%s' "$1" "$name-$version" + printf '
  • \n' +} +html_head() { + printf '\n' + printf '%s\n' "$title" + printf '\n' \ + "$NIX_GHC_DOCDIR/libraries/ocean.css" + printf '

    %s

    \n' "$header" + printf '\n' + printf 'graph\n' "$svg_file" +} + +main "$@"