Skip to content

Instantly share code, notes, and snippets.

@madskjeldgaard
Last active April 9, 2020 14:12
Show Gist options
  • Save madskjeldgaard/4ef63b80ff693bc9d7ec04c16b7c22b4 to your computer and use it in GitHub Desktop.
Save madskjeldgaard/4ef63b80ff693bc9d7ec04c16b7c22b4 to your computer and use it in GitHub Desktop.
Nannou project generator bash script
#!/usr/bin/env bash
#
# A script for generating nannou projects
#
# Usage: newnannou <projectname>
# If you set the environment variable NANNOU_DIR to the path
# of your nannou projects folder, this will be used, otherwise
# the target folder is your home folder
#
# by Mads Kjeldgaard 2020
# Basic Nannou project code taken from the documentation
BASIC_PROJECT_CODE="use nannou::prelude::*;
fn main() {
nannou::app(model)
.update(update)
.simple_window(view)
.run();
}
struct Model {}
fn model(_app: &App) -> Model {
Model {}
}
fn update(_app: &App, _model: &mut Model, _update: Update) {
}
fn view(_app: &App, _model: &Model, frame: Frame){
frame.clear(PURPLE);
}"
# Don't execute script if a name wasn't supplied as first argument
if [ -z $1 ];
then
echo "error:You need to supply a project name";
echo "Usage: newnannou <projectname> <nannou-version>"
else
# If env variable hasn't been set for Nannou project dir, then just use the home dir
if [[ -z $NANNOU_DIR ]]; then
echo "You haven't setup the NANNOU_DIR environment variable containing the path to your nannou projects folder"
echo "Putting the project in your homefolder instead"
NANNOU_DIR=$HOME
fi
# Project directory
cd $NANNOU_DIR
# Generate project
cargo new "$1"
cd "$1"
# echo "nannou = \"$NANNOUVERSION\"" >> Cargo.toml
echo $(cargo search nannou | grep "Creative Coding Framework for Rust") >> Cargo.toml
echo "$BASIC_PROJECT_CODE" > src/main.rs
# Setup git
echo "# $1" >> README.md
git init && git add . && git commit . -m "first commit"
# Open it all in vim
# nvim README.md Cargo.toml src/* -p;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment