Skip to content

Instantly share code, notes, and snippets.

@Achie72
Created May 18, 2019 13:03
Show Gist options
  • Save Achie72/47608dee6e48cc5c0ec1d90c0db17823 to your computer and use it in GitHub Desktop.
Save Achie72/47608dee6e48cc5c0ec1d90c0db17823 to your computer and use it in GitHub Desktop.
A PICO-8 HTML Updater
#!/bin/bash
# A PICO-8 HTML Updater made by Bela Toth - Achie72
# Helping for automatic local updating the doc files
# for github pages, with default index.html and .js names.
# 2019-05-18
BLUE='\033[0;34m'
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
CART_PATH=/path_to/.lexaloffle/pico-8/carts
DOCS_PATH=/path_to/.lexaloffle/pico-8/carts/docs
PICO_PATH=/path_to/pico-8
EXPORT_FILE=$CART_PATH/export.p8
echo -e "${GREEN}====================================${NC}"
echo -e "${GREEN}PICO-8 HTML Updater${NC}"
echo -e "${GREEN}made by Bela Toth/Achie72${NC}"
echo -e "${GREEN}====================================${NC}"
if [ $# -eq 0 ]
then
echo -e "\t${RED}> No arguments supplied.${NC}"
echo -e "\t> Please run script as:"
echo -e '\n\t updateDocs.sh example_name.p8'
echo -e '\n\t OR use -h for help'
exit 1
fi
if [ "$1" == "-h" ] || [ "$1" == "-help" ]
then
echo -e "Usage:"
echo -e "\t-h OR -help: \tStarts help"
echo -e "\t-r OR -run: \tRuns the file after updating"
echo -e '\n\t $1: \tmarks the target cart name as: example.p8'
echo -e '\n\t $2 [-run] \tRun the generated file in default browser'
exit 0
fi
echo -e "${BLUE}Generating export file${NC}"
touch $EXPORT_FILE
echo -e "pico-8 cartridge // http://www.pico-8.com" >> $EXPORT_FILE
echo -e "version 18" >> $EXPORT_FILE
echo -e "__lua__" >> $EXPORT_FILE
echo -e 'load "'${1}'"' >> $EXPORT_FILE
echo -e 'export "index.html"' >> $EXPORT_FILE
echo -e "${BLUE}Generating" ${1}${NC}
$PICO_PATH/pico8 -x $EXPORT_FILE
echo -e "${BLUE}Removing old files from Docs${NC}"
if [ -f $DOCS_PATH/index.html ]
then
echo -e "Removing index.html"
rm $DOCS_PATH/index.html
else
echo -e "Old index.html did not exist"
fi
if [ -f $DOCS_PATH/index.js ]
then
echo -e "Removing index.html"
rm $DOCS_PATH/index.js
else
echo -e "Old index.js did not exist"
fi
echo -e "${BLUE}Placing new files into Docs${NC}"
cp index.html $DOCS_PATH/index.html
cp index.js $DOCS_PATH/index.js
echo -e "${BLUE}Export Cleanup${NC}"
rm $EXPORT_FILE
echo -e "\n${GREEN}DONE${NC}\n"
if [ "$2" == "-run" ]
then
xdg-open $DOCS_PATH/index.html
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment