: '
'
NOTYP=false
NOWGET=false
NOWATCH=false
NEWSTYLE=false
NEWTEXT=false
typst --version &> /dev/null || NOTYP=true
wget --version &> /dev/null || NOWGET=true
which entr &> /dev/null || NOWATCH=true
$NOTYP && echo "please, install typst before proceeding";
$NOWGET && echo "please, install wget before proceeding";
$NOWATCH && echo "please, install entr before proceeding";
$NOTYP && exit
$NOWGET && exit
base=https://raw.githubusercontent.com/snlxnet/YapTyp/refs/heads/main
echo Downloading...
test -f main.typ || NEWSTYLE=true
test -f main.typ || NEWTEXT=true
$NEWSTYLE && wget $base/styles.css &> /dev/null
$NEWTEXT && wget $base/main.typ &> /dev/null
mkdir -p ~/.cache/yaptyp
cd ~/.cache/yaptyp/
wget $base/head.html &> /dev/null
wget $base/mid.html &> /dev/null
wget $base/tail.html &> /dev/null
wget $base/bundle.sh &> /dev/null
cd - &> /dev/null
wget $base/yap.typ &> /dev/null
echo 'YAPTYP_DIR=~/.cache/yaptyp' > bundle.sh
echo -e "\nclear\n" >> bundle.sh
cat ~/.cache/yaptyp/bundle.sh >> bundle.sh
$NEWSTYLE && echo "Created main.typ (edit this one)"
$NEWTEXT && echo "Created styles.css (for the article)"
echo "Watching main.typ for changes..."
sleep 2s
ls main.typ | entr sh bundle.sh
rm -rf ~/.cache/yaptyp
rm bundle.sh yap.typ
echo "Cleaned up"