#!/bin/bash

# eval $(grep LANG $HOME/.profile)
eval $(grep XDG_DOCUMENTS_DIR /etc/environment)
cd $XDG_DOCUMENTS_DIR/$(gettext "Calendar")
year=$(date +%Y)
next=$(( year + 1 ))
calendar="$(gettext "Appointment Calendar")"
path=$XDG_DOCUMENTS_DIR/$(gettext "Calendar")/$calendar-$year
if [ ! -f "./$calendar-$year.ods" ]; then
    cp ./$calendar-Template.ods ./$calendar-$year.ods
fi
if [ ! -f "./$calendar-$next.ods" ]; then
    cp ./$calendar-Template.ods ./$calendar-$next.ods
fi
id=$(wunwa "LibreOffice Calc") && sh -c "xseticon -id $id ~/.icons/kalender.png; orient-act-win 8" && place-window $id 1 0 1182 903 $((($(dims | head -1 | cut -d'|' -f1)-1182)/2)) 18 & GTK_THEME=Arc libreoffice --calc --quickstart --nologo "./$calendar-$year.ods"
rm $path.csv
soffice --headless --convert-to csv:"Text - txt - csv (StarCalc)":9,,76 $path.ods --outdir $XDG_DOCUMENTS_DIR/$"Calendar" $path.csv
sed -i '1d' $path.csv
sed -i 's@\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t@@g' $path.csv
sed -i 's@\t\t@\t \t@g' $path.csv; sed -i 's@\t\t@\t \t@g' $path.csv
[ -d "/home/benutzer/Starbuntu/Webseite" ] && /home/benutzer/Dokumente/Kalender/upload
