Skip to content

Instantly share code, notes, and snippets.

@mcilloni
Created December 15, 2014 15:37
Show Gist options
  • Save mcilloni/942002e0c896c0ec08ed to your computer and use it in GitHub Desktop.
Save mcilloni/942002e0c896c0ec08ed to your computer and use it in GitHub Desktop.
Removes comics sans from PDF files inside the current directory, replacing it with Helvetica.
#!/usr/bin/env fish
set OUTDIR "$PWD/out"
and mkdir -p $OUTDIR
function decomicsansify -d 'Removes that horrible crap'
grep -Rl ComicSansMS | while read TOPURGE
echo Purging $TOPURGE
sed -i s/ComicSansMS/Helvetica/g $TOPURGE
end
return 0
end
function repack -d 'Repacks the ODG contents into a pdf'
zip -0 -X "$argv" mimetype
and zip -r "$argv" * -x mimetype
and soffice --headless --convert-to pdf "$argv"
and mv (echo $argv | sed s/odg/pdf/g) $OUTDIR
end
function usage
echo 'Usage:' (basename (status -f)) "{extract|convert|purge}"
end
function purge
rm -f *.pdf *.odg
and mv out/*.pdf .
and rm -rf out
end
if test (count $argv) -ne 1
usage
exit 1
end
switch $argv
case extract
soffice --headless --convert-to odg *.pdf
case convert
for ODG in *.odg
set BNAME (echo $ODG | perl -wnE 'say $1 if /(.*)\.odg/')
and set WDIR "$BNAME"_wdir
and rm -rf $WDIR
and mkdir -p $WDIR
and pushd $WDIR
and unzip ../$ODG
and decomicsansify
and repack "$ODG"
and popd
and rm -rf $WDIR
or break
end
case purge
purge
case '*'
echo Error: $argv unknown >&2
usage
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment