#!/bin/bash
##########################################################################
# Config my Git
# svg, png, jpg, gif, pdf, docx, odt, ods, odp
# by Dymaxion.Kim@gmail.com
# 20181130 : 1st version for Ubuntu 18.04
##########################################################################
# Make Directory for Scripts
mkdir -p ~/.config/git/ext
# office2pdf Script
OFFICE=${HOME}/.config/git/ext/office2pdf
echo '#!/bin/bash' > ${OFFICE}
echo 'for FILE in `ls $1`; do' >> ${OFFICE}
echo ' if [ ${FILE##*.} = "docx" ]; then' >> ${OFFICE}
echo ' echo "$FILE"' >> ${OFFICE}
echo ' soffice --headless --convert-to pdf $FILE' >> ${OFFICE}
echo ' fi' >> ${OFFICE}
echo ' if [ ${FILE##*.} = "pptx" ]; then' >> ${OFFICE}
echo ' echo "$FILE"' >> ${OFFICE}
echo ' soffice --headless --convert-to pdf $FILE' >> ${OFFICE}
echo ' fi' >> ${OFFICE}
echo ' if [ ${FILE##*.} = "odt" ]; then' >> ${OFFICE}
echo ' echo "$FILE"' >> ${OFFICE}
echo ' soffice --headless --convert-to pdf $FILE' >> ${OFFICE}
echo ' fi' >> ${OFFICE}
echo ' if [ ${FILE##*.} = "odp" ]; then' >> ${OFFICE}
echo ' echo "$FILE"' >> ${OFFICE}
echo ' soffice --headless --convert-to pdf $FILE' >> ${OFFICE}
echo ' fi' >> ${OFFICE}
echo 'done' >> ${OFFICE}
echo '' >> ${OFFICE}
chmod +x ${OFFICE}
# Execute Once
BASHRC=${HOME}/.bashrc
echo '# office2pdf' >> ${BASHRC}
echo 'export PATH="~/.config/git/ext:$PATH"' >> ${BASHRC}
echo '' >> ${BASHRC}
# Diff Images Script
IMAGE=${HOME}/.config/git/ext/diffimg
echo '#!/bin/bash' > ${IMAGE}
echo '# Diff Images (svg,png,jpg,gif)' >> ${IMAGE}
echo 'compare -verbose -fuzz 3% $2 $1 png:- | montage -geometry +4+4 $2 - $1 png:- | display -antialias -title "$1" -' >> ${IMAGE}
echo '' >> ${IMAGE}
chmod +x ${IMAGE}
## ~/.gitconfig
git config --global core.attributesfile ~/.config/git/gitattributes
git config --global diff.word.textconv catdoc
git config --global diff.odf.textconv odt2txt
git config --global diff.diffimg.command ${HOME}/.config/git/ext/diffimg
git config --global diff.diffpdf.command diffpdf
git config --global alias.diffimg 'difftool -y -t diffimg'
#git config --global alias.diffpdf 'difftool -y -t diffpdf'
## ~/.gitattributes
ATTR=${HOME}/.config/git/gitattributes
echo '## Diff Extensions' > ${ATTR}
echo '*.docx diff=word' >> ${ATTR}
echo '*.ods diff=odf' >> ${ATTR}
echo '*.odt diff=odf' >> ${ATTR}
echo '*.odp diff=odf' >> ${ATTR}
echo '*.svg diff=images' >> ${ATTR}
echo '*.png diff=images' >> ${ATTR}
echo '*.jpg diff=images' >> ${ATTR}
echo '*.jpeg diff=images' >> ${ATTR}
echo '*.gif diff=images' >> ${ATTR}
echo '*.pdf diff=pdf' >> ${ATTR}
echo '' >> ${ATTR}
echo "Finished !"
exit 0